2014-09-04 85 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" 
    } 
} 
'@