Multiline curl command

时间:2015-09-01 21:20:25

标签: post curl request http-post

I am trying to modify a curl request that was captured with Google Chrome Dev Tools.

Here is what the command looks like

curl "http://WEBSITE" -H "Host: WEBSITE" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" -H "Accept-Language: en-US,en;q=0.5" --compressed -H "Content-Type: multipart/form-data; boundary=---------------------------1184875127259" --data-binary "-----------------------------1184875127259"^

"Content-Disposition: form-data; name=""FORM1"""^

"FORM1DATA"^
"-----------------------------1184875127259"^

"Content-Disposition: form-data; name=""FORM2"""^

"FORM2DATA"^
"-----------------------------1184875127259"^

"Content-Disposition: form-data; name=""FORM3"""^

"FORM3DATA"^
"-----------------------------1184875127259"^

"Content-Disposition: form-data; name=""embed"""^

"true"^
"---------------------------1184875127259--"^
""

Form# is the name of the form and Form#Data is the data I submitted in the forms.

How would I make this be a single line curl request I can just copy into my command line and have it do the same thing that my browser did?

4 个答案:

答案 0 :(得分:21)

Use the \ escape character for multiline inputs

curl "http://WEBSITE" -H "Host: WEBSITE"\
-H "Accept: text/html,application/xhtml+xml\
,application/xml;q=0.9,*/*;q=0.8" 

答案 1 :(得分:2)

相当于 \ 的 Windows 是 ^

答案 2 :(得分:0)

  

注意:注意多行命令缩进的趋势,   因为它将嵌入空间并拧紧curl命令。 sed   命令用%20替换变量中的嵌入空格   字符串,以便可以在您传递的字符串中嵌入空格   变量

row=0

答案 3 :(得分:0)

如果您正在运行Windows,我发现安装Git和使用Git Bash运行Curl更容易。最初是在另一篇文章https://stackoverflow.com/a/57567112/5636865中提出的。