将带括号的网址传递到curl [英] Passing a URL with brackets to curl

查看:97
本文介绍了将带括号的网址传递到curl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我尝试将网址传递到包含括号的curl,则会失败并显示错误:

  $ curl'http ://www.google.com/?TEST [] = 1'
curl:(3)[globbing] pos 29范围规范中的非法字符
  $ curl'http://www.google.com/?TEST\ [\]=1'

有趣的是,我使用一个反斜杠来逃避 第一个括号,它失败时失败,错误代码为20497:

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

我的问题是如何解决这个一般情况?是否有自动转义URL的参数,或者在传递curl之前需要转义的字符的描述?

解决方案

Nevermind,我发现它在文档:

  -g /  -  globoff 
此选项关闭 URL globbing解析器。当您设置此选项时,您可以
指定包含字母{} []的URL,而不必由curl
本身解释。注意,这些字母不是正常的合法URL内容,而是应根据URI标准编码的


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'

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

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?

解决方案

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

这篇关于将带括号的网址传递到curl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆