如果我尝试将URL传递给包含括号的curl,则会失败并显示错误:
$ curl 'http://www.google.com/?TEST[]=1'
curl: (3) [globbing] illegal character in range specification at pos 29
Run Code Online (Sandbox Code Playgroud)
但是,如果我逃避两个括号,它似乎工作:
$ curl 'http://www.google.com/?TEST\[\]=1'
Run Code Online (Sandbox Code Playgroud)
有趣的是,我使用反斜杠逃脱只有第一托架它与错误代码20497默默地失败:
$ curl 'http://www.google.com/?TEST\[]=1'
$ echo $!
20497
Run Code Online (Sandbox Code Playgroud)
我的问题是如何解决一般情况?是否存在会自动转义URL的参数,或者在传递给curl之前需要转义的字符的描述?
cha*_*imp 450
没关系,我在文档中找到了它:
-g/--globoff
This option switches off the "URL globbing parser". When you set this option, you can
specify URLs that contain the letters {}[] without having them being interpreted by curl
itself. Note that these letters are not normal legal URL contents but they should be
encoded according to the URI standard.
Run Code Online (Sandbox Code Playgroud)
Globbing使用方括号,因此需要用斜线将它们转义\。或者,以下命令行开关将禁用通配符:
--globoff(或短选项版本:-g)
前任:
curl --globoff https://www.google.com?test[]=1
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
99219 次 |
| 最近记录: |