传递带括号的 URL 以卷曲 [英] Passing a URL with brackets to curl
本文介绍了传递带括号的 URL 以卷曲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我尝试将包含括号的 URL 传递给 curl,它会失败并显示错误:
If I try to pass a URL to curl that contains brackets, it fails with an error:
$ 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'
有趣的是,我使用反斜杠来转义仅第一个括号它以错误代码 20497 静默失败:
Interestingly, I use a backslash to escape only the first bracket it fails silently with error code 20497:
$ curl 'http://www.google.com/?TEST[]=1'
$ echo $!
20497
我的问题是如何在一般情况下解决这个问题?是否有一个参数会自动转义 URL,或者在传递给 curl 之前需要转义的字符的描述?
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?
推荐答案
没关系,我在文档中找到了:
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 以卷曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文