2

我需要在 Jira 中自动插入问题,所以我需要使用 REST API,我从命令行运行 curl,这是我的命令

C:\WINDOWS\system32>curl.exe -D- -u fred:fred -X POST --data { "fields": {"project": { "key"="ZZZ-180" }, "summary": "REST TESTING" , "description": "Creation of a testing issue" , "issuretype" { "name": "Bug"}}} -H "Content-Type: application/json" http://ABCD.com:XXXX/rest/api/2/issue/

这是我收到的:

curl: (6) Could not resolve host: fields
curl: (3) [globbing] unmatched brace at pos 10
curl: (3) [globbing] unmatched brace at pos 2
curl: (6) Could not resolve host: key=
curl: (6) Could not resolve host: ZZZ-180
curl: (3) [globbing] unmatched close brace/bracket at pos 1
curl: (6) Could not resolve host: summary
curl: (6) Could not resolve host: REST TESTING
curl: (6) Could not resolve host: ,
curl: (6) Could not resolve host: description
curl: (6) Could not resolve host: Creating of a testing issue
curl: (6) Could not resolve host: ,
curl: (6) Could not resolve host: issuretype
curl: (3) [globbing] unmatched brace at pos 2
curl: (6) Could not resolve host: name
curl: (3) [globbing] unmatched close brace/bracket at pos 4

谁能帮我让 cURL 定义用数据编写的 JSON 代码?

4

2 回答 2

3

您必须引用字符串,但最简单的方法是将 JSON 数据放入文件中并要求 cURL 从中读取:

C:\WINDOWS\system32>curl.exe -D- -u fred:fred -X POST --data @data_to_send.json -H "Content-Type: application/json" http://ABCD.com:XXXX/rest/api/2/issue/

注意@前面的文件名。

于 2013-06-26T13:10:27.370 回答
0

您的 --data 应该类似于:

"{ \"fields\": {\"project\": { \"key\"=\"ZZZ-180\" }, \"summary\": \"REST TESTING\" , \"description\": \"Creation of a testing issue\" , \"issuretype\" { \"name\": \"Bug\"}}}"
于 2016-04-21T18:11:31.530 回答