curl返回400个不带引号的错误请求 [英] curl returns 400 bad request without quotes
本文介绍了curl返回400个不带引号的错误请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
curl -v 'something.com:12684/CAB/keyfile?r=ORE_0&t=VOD&p=1'
返回200,但使用
curl -v something.com:12684/CAB/keyfile?r=ORE_0&t=VOD&p=1
返回400。为什么引号很重要?
returns a 400. Why do the quotes matters?
推荐答案
您的URL包含您的Shell识别为特殊字符。 &
最有可能,这是向UNIX类shell发出的将命令置于后台的信号。因此,您实际上在执行三个命令:
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
您没有看到任何shell错误输出,因为最后两个是有效的shell构造。
You're not seeing any shell error output, because the last two are valid shell constructs.
总是引用您的参数。如果使用PHP,请使用 escapeshellarg
一个>。最好使用 curl
内置库或第三方库,例如枪口。
Always quote your arguments. If in PHP, use escapeshellarg
. Better, use the curl
built-in or a third-party library like Guzzle.
这篇关于curl返回400个不带引号的错误请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文