简体   繁体   中英

curl returns 400 bad request without quotes

curl -v 'something.com:12684/CAB/keyfile?r=ORE_0&t=VOD&p=1'

returns a 200, but using

curl -v something.com:12684/CAB/keyfile?r=ORE_0&t=VOD&p=1

returns a 400. Why do the quotes matters?

Your URL has characters your shell recognizes as special. Most likely, the & , which is the signal to UNIX-ish shells to place the command in the background. So you effectively are executing three commands:

curl -v something.com:12684/CAB/keyfile=?r=ORE_0
t=VOD
p=1

You're not seeing any shell error output, because the last two are valid shell constructs.

Always quote your arguments. If in PHP, use escapeshellarg . Better, use the curl built-in or a third-party library like Guzzle .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM