2014-09-04 83 views
0

我有一些JSON,我正在尝试使用卷曲。在PowerShell中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 

我用[char]39因为我不能在变量使用'字符。

我想使用JIRA Rest API和PowerShell发布此JSON。 我已经检查过JSON的格式和卷曲是否正常(在Linux主机上测试过)。 不幸的是,下面的命令不适合我。

curl https://jira.internal/rest/api/2/issue/ -f -u user:[email protected]! -H "Content-type:application/json" -X POST -d $json 
+1

'不行'告诉我们很少。你会得到什么错误? – 2014-09-04 13:06:54

+0

嗨耶利米,我得到了400不好的请求这是非常非常奇怪的,因为当我在Linux主机上做同样的操作时,一切都像魅力一样。我认为这可能是编码问题,因为当我将这个JSON导出为UTF-8编码文件并将该文件转换为cURL时,它可以工作。但我不知道如何在PowerShell变量上设置编码来检查它我搜索了很多,但没有找到解决方案。 – Dominik 2014-09-04 13:26:31

回答

0

我在Windows面临着同样的问题在PowerShell的4.0,并通过 linebrackets和 “@” 符号来解决它。请尝试以下方法:

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