简体   繁体   English

CURL POST 到 JIRA

[英]CURL to POST to JIRA

I am using curl command in powershell in my Windows machine.我在 Windows 机器的 powershell 中使用 curl 命令。 I am trying to create an issue in JIRA which I have installed in my local.我试图在我本地安装的 JIRA 中创建一个问题。 I tried following but it throws me error.我尝试跟随,但它引发了我的错误。 Can someone let me know what am I missing and how to fix it?有人可以让我知道我缺少什么以及如何解决它吗?

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
*

When I try following I get this error:当我尝试以下时,我收到此错误:

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*

And hence I tried $ instaed of @ in file name.因此我在文件名中尝试了$ instaed 的@

"parse.json" File has following content: "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"
       }
   }
}

As this is windows machine, I also tried using slash (/) in parse.json file (saw in few posts that / will remove the error) but that also did not help.由于这是 Windows 机器,我还尝试在 parse.json 文件中使用斜杠 (/)(在几篇文章中看到 / 将删除错误)但这也没有帮助。 Please can someone let me know how to fix this?请问有人可以让我知道如何解决这个问题吗?

In the first case在第一种情况下

curl -D- -u raji:raji -X POST --data $parse.json -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue

$parse is interpreted by powershell as variable, $parse.json as attribute json of the variable $parse , which does not exist, so the command executed would be $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 is -H , and the content type header is interpreted as url to access. data 是-H ,内容类型标头被解释为要访问的 url。

In the second case the @ in powershell is interpreted as splat operator , if you want a literal @ (which is interperted by curl and not by powershell), simply quote the string:在第二种情况下,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

Now it should use the contents of the file parse.json as data.现在它应该使用文件parse.json的内容作为数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM