命令提示符无法转义引号和大括号

kyp*_*hos 39 quotes command escaping prompt curly-braces

我试图在命令提示符中执行以下行:

curl -X POST -d '{ "method" : "account_info", "params" : [ { "account" : "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh"} ] }' http://s1.ripple.com:51234
Run Code Online (Sandbox Code Playgroud)

但是,我得到以下内容:

curl: (6) Could not resolve host: method
curl: (7) Failed connect to :80; No error
curl: (6) Could not resolve host: account_info,
curl: (6) Could not resolve host: params
curl: (7) Failed connect to :80; No error
curl: (3) [globbing] illegal character in range specification at pos 2
curl: (3) [globbing] unmatched brace at pos 2
curl: (6) Could not resolve host: account
curl: (7) Failed connect to :80; No error
curl: (3) [globbing] unmatched close brace/bracket at pos 35
curl: (3) [globbing] unmatched close brace/bracket at pos 1
curl: (3) [globbing] unmatched close brace/bracket at pos 1
unable to parse request
Run Code Online (Sandbox Code Playgroud)

我在Windows上,错误与引号,大括号和globbing有关.我尝试使用反斜杠来避免引号,没有运气.

我确信我只需要以正确的方式逃避正确的事情,但我很难做到这一点.一些帮助将受到高度赞赏.

Man*_*ich 57

试试这个:

curl -X POST -d "{ \"method\" : \"account_info\", \"params\" : [ { \"account\" : \"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh\"} ] }" http://s1.ripple.com:51234
Run Code Online (Sandbox Code Playgroud)

  • 哇有效; 所以诀窍是不使用单引号,并转义字符串中的任何双引号?谢啦! (7认同)
  • 是的,window的command.exe似乎不支持单引号.PowerShell可以,但是在使用它们时仍然存在一些问题,因此最好的解决方案是根本不使用它们. (3认同)
  • @ManuelGörlich,非常感谢你!:) (2认同)
  • 你怎么能在那里插入环境变量呢?类似于 { \"account/": $ACCOUNT_KEY } (2认同)

can*_*ndu 36

你可以curl -g用来关闭globbing:

curl -g -X POST -d '{ "method" : "account_info", "params" : [ { "account" : "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh"} ] }' http://s1.ripple.com:51234
Run Code Online (Sandbox Code Playgroud)

比逃避所有这些括号更容易.

  • 不适合我.逃避工作,转换为globbing仍然让我有400错误.不过,在某些情况下,这仍然是一个很好的答案. (2认同)