我發送POST請求到我的JSON數據用於創建項目,但我無法創建一個項目到JIRA,我試圖看到來自提琴手的錯誤,我有以下錯誤。我正在使用C#併爲其創建控制檯應用程序。如何使用REST API創建問題到JIRA?
我發佈的JSON數據如下。
{
"fields": {
"project": {
"key": "JTL"
},
"issuetype": {
"name": "BUG"
}
}
}
錯誤消息是下列:
{ 「errorMessages」:[], 「錯誤」:{ 「問題類型」: 「問題類型是必需的」}}
我我從以下代碼發佈json數據,請提出什麼和我哪裏錯了?
string [email protected]"{"fields":{"project":{"key":"JTL"},"issuetype":{"name":"BUG"}}}";
//object of HttpClient.
HttpClient client = new HttpClient();
//Putting URI in client base address.
client.BaseAddress = new Uri(uri);
//Putting the credentials as bytes.
byte[] cred = UTF8Encoding.UTF8.GetBytes("jiraUserName" + ":" + "JiraPassword");
//Putting credentials in Authorization headers.
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(cred));
//Putting content-type into the Header.
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
//i am using StringContent because i am creating console application, no any serialize i used for maniputlate the string.
var content = new StringContent(data, Encoding.UTF8, "application/json");
//Sending the Post Request to the server. But getting 400 bad Request.
System.Net.Http.HttpResponseMessage response = client.PostAsync("issue", content).Result;
在上面的代碼中,您可以看到我正在發送授權用戶和發送數據的憑據。
您是否100%肯定您的JSON輸出數據包含'issuebug'鍵? – 2014-10-29 07:08:55
是的,因爲我的積極性有理由,在我當前的JSON描述和夏季鍵都不存在,但是當我發送JSON數據與兩個鍵比響應是「夏日」和「描述」是不知道或不是必需的,比我刪除了這兩個鍵值,但在JIRA REST api文檔中,這兩個鍵都用於示例演示。 – 2014-10-29 07:14:25
您確定您正在訪問正確的端點嗎?意味着正確的URL? – 2014-10-29 07:16:16