Batch file 如何从windows批处理脚本通过curl发送带有json正文的POST请求
我正在编写批处理脚本,它应该使用json发送请求Batch file 如何从windows批处理脚本通过curl发送带有json正文的POST请求,batch-file,curl,cmd,git-bash,windows-console,Batch File,Curl,Cmd,Git Bash,Windows Console,我正在编写批处理脚本,它应该使用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 我从git bash运行脚本,虽然它发送了请求
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
我从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
以下是身体的外观:
'{"text":
这是不对的
正如您所看到的,我是从变量中编写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
同样的错误也会发生
然而,当我从批处理脚本复制这个命令并将其直接粘贴到git bash控制台时,它可以无缝地工作。不要问我为什么要从GitBash运行windows批处理脚本,因为我可以使用bash语言编写bash脚本,而不是使用笨拙和混乱的DOS语法。我没有意识到,当我开始写剧本的时候,它几乎完成了(除了这一部分)。如何让它工作?谢谢 试试看:
curl-X POST-H“内容类型:application/json”--数据“{\”text\:\”拉取请求已部署到\“,\”用户名\“:\”暂存服务器\“}”http://requestb.in/ovehwtov
显然,有了正确的数据
如果您在Windows上,则必须在cmd解释命令中使用“\”,包含空格的标记需要用双引号括起来。请尝试
call curl-X POST-H“内容类型:应用程序/json”--数据“{'text':'Pull请求:\n%linksText%已部署到%stagingServerUrl%,'username':'stagingserver'}”http://requestb.in/ovehwtov
。谢谢您,好先生。虽然json中不允许使用单引号,但它应该是call curl-X POST-H“Content type:application/json”--数据“{\“text\”:\“Pull requests:\n%linksText%已部署到%stagingServerUrl%\”,\“username\”:“Staging Server\”}http://requestb.in/qkebavqk