开发者

correctly formatting a curl url with URL strings

I'm trying to get curl to use a url of the following form:

http://www.example.com?a=1&b=2

However, consistently it's only going to开发者_JAVA技巧 http://www.example.com?a=1, which I can tell by using the -v flag.

The command I'm using is:

curl http://www.example.com?a=1&b=2

How do I correctly use curl for multiple URL strings in my query?


The "&" is being intercepted by your shell (which tries to make it run in the background, which you may not notice since it will still output to the same console). Try quoting the URL:

curl 'http://www.example.com?a=1&b=2'

When in doubt, try passing all of your arguments to echo instead, and see what happens. Here's a sample transcript from my shell:

$ echo foo&bar
[1] 18759
foo
bash: bar: command not found
[1]+  Done                    echo foo
$ echo foo\&bar
foo&bar
$ echo "foo&bar"
foo&bar
$ echo 'foo&bar'
foo&bar
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜