简体   繁体   English

curl返回400个不带引号的错误请求

[英]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 返回200,但使用

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

returns a 400. Why do the quotes matters? 返回400.为什么报价很重要?

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. 最有可能的是& ,这是UNIX-ish shell的信号,用于将命令放在后台。 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. 您没有看到任何shell错误输出,因为最后两个是有效的shell构造。

Always quote your arguments. 总是引用你的论点。 If in PHP, use escapeshellarg . 如果在PHP中,请使用escapeshellarg Better, use the curl built-in or a third-party library like Guzzle . 更好,使用内置的curl或像Guzzle这样的第三方库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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