CURL 到 POST 到 JIRA
CURL to POST to JIRA
我在 Windows 机器的 powershell 中使用 curl 命令。我正在尝试在本地安装的 JIRA 中创建一个问题。我试过跟随但它抛出错误。有人可以告诉我我缺少什么以及如何解决吗?
PS C:\Users\raji> **curl -D- -u raji:raji -X POST --data $parse.json -H
"Content-Type: application/json" http://localhost:8080/rest/api/2/issue**
*curl: (6) Could not resolve host: Content-Type
HTTP/1.1 415 Unsupported Media Type
Server: Apache-Coyote/1.1
X-AREQUESTID: 770x749x1
X-ASEN: SEN-L8183526
Set-Cookie: JSESSIONID=D0B4391C94413FDDB1291C419F3E1360; Path=/; HttpOnly
X-Seraph-LoginReason: OK
Set-Cookie: atlassian.xsrf.token=B3EL-GHY4-P1TP-IMD0|d3d735e0a6566f8a97f99c96e80042551def3192|lin; Path=/
X-ASESSIONID: 1v4terf
X-AUSERNAME: raji
X-Content-Type-Options: nosniff
Content-Type: text/html;charset=UTF-8
Content-Length: 0
Date: Sun, 10 Jul 2016 07:20:36 GMT
*
当我尝试跟随时出现此错误:
PS C:\Users\raji> **curl -D- -u raji:raji -X POST --data @parse.json -H
"Content-Type: application/json" http://localhost:8080/rest/api/2/issue**
*At line:1 char:38
+ curl -D- -u raji:raji -X POST --data @parse.json -H "Content-Type: ap ...
+ ~~~~~~
The splatting operator '@' cannot be used to reference variables in an expression. '@parse' can be used only as an argument to a command. To reference variables in an expression use '$parse'.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : SplattingNotPermitted*
因此我尝试在文件名中 $
代替 @
。
"parse.json"
文件包含以下内容:
{
"fields": {
"project":
{
"key": "Demo"
},
"summary": "REST ye merry gentlemen",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Bug"
}
}
}
因为这是 windows 机器,我也尝试在 parse.json 文件中使用斜杠 (/)(在一些帖子中看到 / 将删除错误)但这也没有帮助。有人可以告诉我如何解决这个问题吗?
第一种情况
curl -D- -u raji:raji -X POST --data $parse.json -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue
$parse
被 powershell 解释为变量,$parse.json
被解释为变量 $parse
的属性 json
,它不存在,因此执行的命令将是
curl -D- -u raji:raji -X POST --data -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue
data为-H
,content type header被解释为url访问。
在第二种情况下,powershell 中的 @
被解释为 splat operator,如果您想要文字 @
(由 curl 而不是由powershell),只需引用字符串:
curl -D- -u raji:raji -X POST --data "@parse.json" -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue
现在它应该使用文件 parse.json
的内容作为数据。
我在 Windows 机器的 powershell 中使用 curl 命令。我正在尝试在本地安装的 JIRA 中创建一个问题。我试过跟随但它抛出错误。有人可以告诉我我缺少什么以及如何解决吗?
PS C:\Users\raji> **curl -D- -u raji:raji -X POST --data $parse.json -H
"Content-Type: application/json" http://localhost:8080/rest/api/2/issue**
*curl: (6) Could not resolve host: Content-Type
HTTP/1.1 415 Unsupported Media Type
Server: Apache-Coyote/1.1
X-AREQUESTID: 770x749x1
X-ASEN: SEN-L8183526
Set-Cookie: JSESSIONID=D0B4391C94413FDDB1291C419F3E1360; Path=/; HttpOnly
X-Seraph-LoginReason: OK
Set-Cookie: atlassian.xsrf.token=B3EL-GHY4-P1TP-IMD0|d3d735e0a6566f8a97f99c96e80042551def3192|lin; Path=/
X-ASESSIONID: 1v4terf
X-AUSERNAME: raji
X-Content-Type-Options: nosniff
Content-Type: text/html;charset=UTF-8
Content-Length: 0
Date: Sun, 10 Jul 2016 07:20:36 GMT
*
当我尝试跟随时出现此错误:
PS C:\Users\raji> **curl -D- -u raji:raji -X POST --data @parse.json -H
"Content-Type: application/json" http://localhost:8080/rest/api/2/issue**
*At line:1 char:38
+ curl -D- -u raji:raji -X POST --data @parse.json -H "Content-Type: ap ...
+ ~~~~~~
The splatting operator '@' cannot be used to reference variables in an expression. '@parse' can be used only as an argument to a command. To reference variables in an expression use '$parse'.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : SplattingNotPermitted*
因此我尝试在文件名中 $
代替 @
。
"parse.json"
文件包含以下内容:
{
"fields": {
"project":
{
"key": "Demo"
},
"summary": "REST ye merry gentlemen",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Bug"
}
}
}
因为这是 windows 机器,我也尝试在 parse.json 文件中使用斜杠 (/)(在一些帖子中看到 / 将删除错误)但这也没有帮助。有人可以告诉我如何解决这个问题吗?
第一种情况
curl -D- -u raji:raji -X POST --data $parse.json -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue
$parse
被 powershell 解释为变量,$parse.json
被解释为变量 $parse
的属性 json
,它不存在,因此执行的命令将是
curl -D- -u raji:raji -X POST --data -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue
data为-H
,content type header被解释为url访问。
在第二种情况下,powershell 中的 @
被解释为 splat operator,如果您想要文字 @
(由 curl 而不是由powershell),只需引用字符串:
curl -D- -u raji:raji -X POST --data "@parse.json" -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue
现在它应该使用文件 parse.json
的内容作为数据。