传递带有方括号的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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值