I am developing a module for a web application. To trigger this module, I need to submit some data to the server. For simple forms, Copy as cURL
in the Chrome Developer Tools works fine (using curl from msys[git]), but for post requests with multipart/form-data
, the copied string is neither usable in the windows shell (cmd) nor with bash (form msys); the copied text is similar to:
curl "http://myserver.local" -H "Origin: http://wiki.selfhtml.org" -H "Accept-Encoding: gzip, deflate" -H "Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4" -H "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36" -H "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryntXdlWbYXAVwCIMU" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" -H "Cache-Control: max-age=0" -H "Referer: http://wiki.selfhtml.org/extensions/Selfhtml/frickl.php/Beispiel:HTML_form-Element1.html" -H "Connection: keep-alive" --data-binary "------WebKitFormBoundaryntXdlWbYXAVwCIMU"^ "Content-Disposition: form-data; name=""area"""^ "multi"^ "line"^ "------WebKitFormBoundaryntXdlWbYXAVwCIMU--"^ "" --compressed
Is there any way I could use this or convert it to something usable?
When the -F option is used, curl sends the data using the multipart/form-data Content-Type. Another way to make a POST request is to use the -d option. This causes curl to send the data using the application/x-www-form-urlencoded Content-Type.
From Chrome On the line of the specific resource you're interested in, you right-click with the mouse and you select “Copy as cURL” and it'll generate a command line for you in your clipboard. Paste that in a shell to get a curl command line that makes the transfer.
To use this feature: Load a page with the Network Panel open. Right click on resource and select Copy > Copy as cURL. Paste your clipboard contents into your terminal.
Chrome, as well as the other browsers actually, do a rather poor job of translating multi-part formposts into curl command lines.
A much more convenient curl command line would not use --data-binary
for that, it would use --form
. And then you want one --form
per input field.
In your case, it probably would look something like (backslashes inserted here for visibility):
curl "http://myserver.local" \
--compressed \
-H "Origin: http://wiki.selfhtml.org" \
-A "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36" \
-H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" \
-H "Cache-Control: max-age=0" \
-e "http://wiki.selfhtml.org/extensions/Selfhtml/frickl.php/Beispiel:HTML_form-Element1.html" \
-F area=[contents]
I left the [contents] in there, but it should be replaced with what you actually want in the area
field. You could also pass it from a file if you prefer to.
I removed two unnecessary -H
uses, and I replaced two to use the direct curl options.
Advice for the future: figure out the exact HTTP header trace you want to reproduce with a curl command line and paste it over at https://curl.se/h2c/ .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With