简体   繁体   English

Powershell中的cURL不起作用

[英]cURL in powershell doesn't work

I have some JSON and I am trying to use with curl. 我有一些JSON,并尝试与curl配合使用。

$json = [char]93 + "{"fields":{"project":{"key":"TEST"},"summary":"Test of the REST","description":"Issue created using the REST API","issuetype":{"name":"Bug"}}}` + [char]93

I've used [char]39 because I can't use the ' character in variable. 我使用[char]39是因为我不能在变量中使用'字符。

I'm trying to post this JSON using JIRA Rest API and PowerShell. 我正在尝试使用JIRA Rest API和PowerShell发布此JSON。 I've checked that format of the JSON and the cURL is ok (tested on Linux host). 我检查了JSON的格式,并且cURL正常(在Linux主机上测试)。 Unfortunately the following command doesn't work for me. 不幸的是,以下命令对我不起作用。

curl https://jira.internal/rest/api/2/issue/ -f -u user:p@ssw0rd! -H "Content-type:application/json" -X POST -d $json

I faced the same issue in PowerShell 4.0 in Windows and solved it via linebrackets and "@"symbols. 我在Windows PowerShell 4.0中也遇到了同样的问题,并通过线括号和“ @”符号解决了该问题。 Try following: 请尝试以下操作:

$json= @'
{
   "fields":{
       "project":{"key":"TEST"}
   },
   "summary":"Test of the REST",
   "description":"Issue created using the REST API",
   "issuetype":{
        "name":"Bug"
   }  
}
'@

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

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