传递带有方括号的URL以进行卷曲

本文翻译自:Passing a URL with brackets to curl

If I try to pass a URL to curl that contains brackets, it fails with an error: 如果我尝试将包含括号的URL传递给curl,它将失败并显示错误:

$ curl 'http://www.google.com/?TEST[]=1'
curl: (3) [globbing] illegal character in range specification at pos 29

However, if I escape both brackets, it appears to work: 但是,如果我同时使用了两个括号,它似乎可以工作:

$ curl 'http://www.google.com/?TEST\[\]=1'

Interestingly, I use a backslash to escape only the first bracket it fails silently with error code 20497: 有趣的是,我使用反斜杠转义它在第一个失败时出现的错误代码为20497的第一个括号:

$ curl 'http://www.google.com/?TEST\[]=1'
$ echo $!
20497

My question is how to fix this for general cases? 我的问题是在一般情况下该如何解决? Is there an argument that will escape URLs automatically, or a description of the characters that need to be escaped before passing to curl? 是否存在可以自动转义URL的参数,或者是否存在传递给curl之前需要转义的字符的描述?


#1楼

参考:https://stackoom.com/question/yY24/传递带有方括号的URL以进行卷曲


#2楼

Never mind, I found it in the docs: 没关系,我在文档中找到了它:

-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.

你可能感兴趣的:(传递带有方括号的URL以进行卷曲)