dKa*_*Kab 3 curl cmd batch-file windows-console git-bash
我正在编写应该使用 json 发送请求的批处理脚本。
call curl -X POST -H 'Content-type: application/json' --data '{"text": "Pull requests:\n%linksText% has been deployed to %stagingServerUrl%", "username": "Staging Server"}' http://requestb.in/ovehwtov
Run Code Online (Sandbox Code Playgroud)
我从 git bash 运行我的脚本,虽然它发送了请求,但正文格式不正确,就在它发送请求之前,我在控制台中看到错误:
curl: (6) Couldn't resolve host 'application'
curl: (6) Couldn't resolve host '"Pull'
curl: (6) Couldn't resolve host 'requests:\nhttp'
curl: (6) Couldn't resolve host 'has'
curl: (6) Couldn't resolve host 'been'
curl: (6) Couldn't resolve host 'deployed'
curl: (6) Couldn't resolve host 'to'
curl: (6) Couldn't resolve host 'unicorns2url",'
curl: (6) Couldn't resolve host '"username"'
curl: (6) Couldn't resolve host 'Staging'
curl: (3) [globbing] unmatched close brace/bracket in column 8
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 11 0 2 100 9 6 30 --:--:-- --:--:-- --:--:-- 30ok
Run Code Online (Sandbox Code Playgroud)
这是身体的样子:
'{"text":
Run Code Online (Sandbox Code Playgroud)
这是不对的。
如您所见,我正在从变量中编写 json,但这不是失败的原因:当我删除它们并调用时
call curl -X POST -H 'Content-type: application/json' --data '{"text": "Pull requests has been deployed to", "username": "Staging Server"}' http://requestb.in/ovehwtov
Run Code Online (Sandbox Code Playgroud)
发生同样的错误。
但是,当我从批处理脚本中复制此命令并将其直接粘贴到 git bash 控制台时,它可以无缝运行。不要问我为什么要从 git bash 运行 Windows 批处理脚本,当我可以使用 bash 语言编写 bash 脚本而不是笨拙且令人困惑的 DOS 语法时。我没有意识到,当我开始编写脚本时,它几乎完成了(除了这一部分)。如何使它工作?谢谢!
小智 8
尝试:
curl -X POST -H "Content-type: application/json" --data "{\"text\": \"Pull requests has been deployed to\", \"username\": \"Staging Server\"}" http://requestb.in/ovehwtov
显然有正确的数据。
如果您使用的是 Windows,则必须使用“\”。