如果我试图将包含括号的URL传递给curl,它将失败,并出现错误:
$ curl 'http://www.google.com/?TEST[]=1'
curl: (3) [globbing] illegal character in range specification at pos 29
然而,如果我避开两个括号,它似乎是有效的:
$ curl 'http://www.google.com/?TEST\[\]=1'
我该怎么解决这个问题?是否有将自动转义curl的参数,或者在传递到curl之前需要转义的字符的描述?
发布于 2011-11-30 22:37:42
将-g
添加到命令中:
-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 curl itself interpret them.
Note that these letters are not normal legal URL contents but they should be encoded
according to the URI standard.
Example:
curl -g "https://example.com/{[]}}}}"
发布于 2020-05-19 00:37:24
球状使用括号,因此需要用斜杠\
来转义它们。或者,下面的命令行开关将禁用全局操作:
--globoff
(或短选项版本:-g
)
例如:
curl --globoff https://www.google.com?test[]=1
发布于 2021-01-05 01:21:22
我得到了这个错误,尽管我的URL中没有(明显的)括号,而且在我的情况下-globoff命令不会解决这个问题。
例如(在iTerm2中的mac上执行此操作):
for endpoint in $(grep some_string output.txt); do curl "http://1.2.3.4/api/v1/${endpoint}" ; done
我把grep别名为"grep -color= have“。因此,上述命令将导致此错误,将grep设置为任何颜色的some_string突出显示如下:
curl: (3) bad range in URL position 31:
http://1.2.3.4/api/v1/lalalasome_stringlalala
终端在终端中查看时透明地将colour\codessome_stringcolour\codes转换成预期的非特殊字符URL,但在幕后,在传递给curl的URL中发送颜色代码,导致您的URL中的括号。
解决方案是不使用匹配高亮显示。
https://stackoverflow.com/questions/8333920
复制相似问题