我一直在尝试与 JIRA REST API(版本 = 5.2-m06-4)进行交互
我的代码如下所示:
function ConvertTo-Base64($string) {
$bytes = [System.Text.Encoding]::UTF8.GetBytes($string);
$encoded = [System.Convert]::ToBase64String($bytes);
return $encoded;
}
$reqBody = [System.Text.Encoding]::UTF8.GetBytes($data)
try{
$authenticationDetails = ConvertTo-Base64 '$username:$password'
Write-Host('Opening a connection to {0}' -f $url)
$req = [System.Net.WebRequest]::Create($Url)
$req.Headers.Add("AUTHORIZATION", $headerValue);
$req.Method = "POST"
$req.ContentType = "application/json"
$req.Timeout = $Timeout.TotalMilliseconds
$req.Credentials = New-Object System.Net.NetworkCredential -ArgumentList $username, $password
$req.PreAuthenticate = $true
$req.ContentLength = $reqBody.Length
$reqStream = $req.GetRequestStream()
$reqStream.Write($reqBody, 0, $reqBody.Length)
$reqStream.Close()
Write-Host($data)
$resp = $req.GetResponse()
Write-Verbose $resp
Write-Output $resp.StatusCode
}
catch [System.Net.WebException]{
if ($_.Exception -ne $null -and $_.Exception.Response -ne $null) {
$errorResult = $_.Exception.Response.GetResponseStream()
$errorText = (New-Object System.IO.StreamReader($errorResult)).ReadToEnd()
Write-Warning "The remote server response: $errorText"
Write-Output $_.Exception.Response.StatusCode
Write-Host $_
} else {
throw $_
}
}
代码通过 JSON 传递如下:
$jsonString = '{"fields": {"project":{ "key": "CCB"},"components": "' + $COMPONENT + '"},"customfield_11502" : "' + $DEPLOYMENT_DATE + '" ,"摘要": "' + $description + '","问题类型": {"name": "配置更改"}}}'
我遇到的问题是,当我尝试以这种方式发布数据时,我被告知摘要、customfield_11502 和组件不是屏幕的一部分。当我尝试删除 JSON 的这些属性时,我被告知我无权发布问题。
这里正确的错误信息是什么?是不是我没有被授权,如果是这样,屏幕上缺少的字段是否真的不是问题?
通过 REST API 传递用户名和密码时,我使用 Base64 对其进行编码,并将其传递到标头中。我有什么明显的遗漏吗?