2016-07-10 14 views
1

Ich verwende curl-Befehl in Powershell in meinem Windows-Rechner. Ich versuche, ein Problem in JIRA zu erstellen, das ich in meinem lokalen installiert habe. Ich habe versucht zu folgen, aber es wirft mir einen Fehler. Kann mir jemand sagen, was ich vermisse und wie ich es beheben kann?CURL zu POST zu 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 
* 

Wenn ich versuche folgende bekomme ich diesen Fehler:

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* 

Und daher habe ich versucht, $ von @ in Dateinamen instaed.

"parse.json" Datei hat folgenden Inhalt:

{ 
    "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" 
     } 
    } 
} 

Da es sich um Windows-Maschine, ich habe auch versucht, Schrägstrich (/) in parse.json Datei (saw in wenigen Stellen, die/den Fehler entfernen), aber das hat auch nicht geholfen. Kann mir bitte jemand sagen, wie ich das beheben kann?

+1

Ich habe auch bemerkt, dass in Fehlerausgabe folgenden erwähnt: Content-Type: text/html; charset = UTF-8 Content-Length: 0 In curl Befehl Ich habe als Inhaltstyp erwähnt: „Content-Type : application/json " – Raji

Antwort

1

Im ersten Fall

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

$parse von Power als variable interpretiert wird, $parse.json als Attribut json der Variablen $parse, die nicht vorhanden ist, so ausgeführt, um den Befehl würde

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

Daten sind -H, und der Header des Inhaltstyps wird als URL für den Zugriff interpretiert.

Im zweiten Fall die @ in Powershell als splat operator interpretiert wird, wenn Sie ein wörtliches @ wollen (die von curl interperted und nicht von Powershell), zitieren einfach die Zeichenfolge:

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

Jetzt sollte es Verwenden Sie den Inhalt der Datei parse.json als Daten.

+0

Vielen Dank Mata. Ihre Erklärung hat mir sehr geholfen, meinen Fehler zu verstehen und die von Ihnen zur Verfügung gestellte Korrektur hat auch gut funktioniert. Ich bin in der Lage, ein Problem in JIRA zu erstellen. curl -D- -u raji: raji -X POST -Daten "@ parse.json" -H "Content-Type: application/json" http: // localhost: 8080/rest/api/2/ausgabe – Raji