2017-10-25 3 views
0

Ich habe folgende curl, das funktioniert:Ruby + HTTParty-wie eine POST-Anfrage mit Daten-Binär senden?

curl 'https://externalsite.com/ForgotPasswordSubmit.action' \ 
-X POST \ 
-H 'Content-Type: multipart/form-data; boundary=----qwertyuiop' \ 
--data-binary $'------qwertyuiop\r\nContent-Disposition: form-data; name="xsrf_token"\r\n\r\nnull\r\n------qwertyuiop\r\nContent-Disposition: form-data; name="emailAddr"\r\n\r\[email protected]\r\n------qwertyuiop--\r\n' 

Ich versuche, ein Rubin + Sinatra App zu bekommen, das Gleiche zu tun, aber es funktioniert nicht. Hier ist mein letzter Versuch:

HTTParty.post "https://externalsite.com/ForgotPasswordSubmit.action", :headers => {"Content-Type"=>"multipart/form-data; boundary=----qwertyuiop"}, :body => '------qwertyuiop\r\nContent-Disposition: form-data; name="xsrf_token"\r\n\r\nnull\r\n------qwertyuiop\r\nContent-Disposition: form-data; name="emailAddr"\r\n\r\[email protected]\r\n------qwertyuiop--\r\n' 

Antwort

0

Ich habe es schließlich mit curb zu arbeiten. Das Hauptproblem war, dass curl$'my_string\n' Art von Zeichenfolge \r\n Zeichen in neue Zeilen verwandelt, während in Ruby versuchte ich 'my_string\n', die automatisch zu my_string\\n geparst wurde. Durch die Verwendung von doppelten Anführungszeichen habe ich dieses Problem behoben.

Abschlussarbeitscode lautet:

curl = Curl::Easy.new('https://externalsite.com/ForgotPasswordSubmit.action') 
curl.headers["Content-Type"] = "multipart/form-data; boundary=----qwertyuiop" 
data = "------qwertyuiop\r\nContent-Disposition: form-data; name=\"xsrf_token\"\r\n\r\nnull\r\n------qwertyuiop\r\nContent-Disposition: form-data; name=\"emailAddr\"\r\n\r\n#{email}\r\n------qwertyuiop--\r\n" 
curl.post_body=data 
curl.http_post 
Verwandte Themen