Linux 如何在 curl 请求的数据中发布 URL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18204326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to POST URL in data of a curl request
提问by Vivek Muthal
I am trying to post two parameters using curl
, path
and fileName
:
我正在尝试使用curl
,path
和发布两个参数fileName
:
curl --request POST 'http://localhost/Service' --data "path='/xyz/pqr/test/'&fileName='1.doc'"
I know something is wrong in this. I have to use something like URLEncode. I tried many things still no luck.
我知道这有什么不对的。我必须使用类似 URLEncode 的东西。我尝试了很多事情仍然没有运气。
Please give an example how can I post the url in data of curl request.
请举例说明如何在 curl 请求的数据中发布 url。
采纳答案by konsolebox
Perhaps you don't have to include the single quotes:
也许您不必包含单引号:
curl --request POST 'http://localhost/Service' --data "path=/xyz/pqr/test/&fileName=1.doc"
Update: Reading curl's manual, you could actually separate both fields with two --data:
更新:阅读 curl 的手册,您实际上可以使用两个 --data 将两个字段分开:
curl --request POST 'http://localhost/Service' --data "path=/xyz/pqr/test/" --data "fileName=1.doc"
You could also try --data-binary:
您也可以尝试 --data-binary:
curl --request POST 'http://localhost/Service' --data-binary "path=/xyz/pqr/test/" --data-binary "fileName=1.doc"
And --data-urlencode:
和--data-urlencode:
curl --request POST 'http://localhost/Service' --data-urlencode "path=/xyz/pqr/test/" --data-urlencode "fileName=1.doc"
回答by Patrick
I don't think it's necessary to use semi-quotes around the variables, try:
我认为没有必要在变量周围使用半引号,请尝试:
curl -XPOST 'http://localhost/Service' -d "path=%2fxyz%2fpqr%2ftest%2f&fileName=1.doc"
%2f
is the escape code for a /
.
%2f
是 a 的转义码/
。
http://www.december.com/html/spec/esccodes.html
http://www.december.com/html/spec/esccodes.html
Also, do you need to specify a port? ( just checking :) )
另外,你需要指定一个端口吗?( 只是检查 :) )