How can I rewrite this CURL multipart/form-data re

2019-01-16 04:54发布

How can I rewrite the following CURL command, so that it doesn't use the -F option, but still generates the exact same HTTP request? i.e. so that it passes the multipart/form-data in the body directly.

curl -X POST -F example=test http://localhost:3000/test

7条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-16 05:25

Here's an alternative answer with the original CURL statement re-written using -d as a one-liner, without temporary files. Personally I think the temporary files approach is easier to understand, but I'm putting this here for reference as well:

curl -X POST -H "Content-Type: multipart/form-data; boundary=----------------------------4ebf00fbcf09" -d $'------------------------------4ebf00fbcf09\r\nContent-Disposition: form-data; name="example"\r\n\r\ntest\r\n------------------------------4ebf00fbcf09--\r\n' http://localhost:3000/test

Notes: the $'blar' syntax is so that bash will parse the \r\n as a CRLF token. Thanks to this answer for that tip.

查看更多
登录 后发表回答