簡體   English   中英

JIRA Rest API 405 拒收 C#

[英]JIRA Rest API 405 rejection C#

我正在嘗試使用 REST API 通過 C# 在我的 JIRA 服務器實例中創建一個問題。

我可以使用 REST 很好地檢索數據,但是當我嘗試創建時,我也會收到 405 錯誤,原因是短語 405。

到目前為止,我已經嘗試了在 Google 上找到的解決方案,包括使用 https 而不是 http,我可以確認我的憑據是正確的。

我真的被困住了,所以任何幫助都會很棒!

文檔: https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/

   public string CreateJiraIssue()
    {

        string data = @"{ ""fields"": { 
                                        ""project"":
                                           {
                                               ""key"": ""TESTREST""
                                           },
                                        ""summary"": ""Test Ticket"",
                                        ""description"": ""Creating of an issue using project keys and issue type names using the REST API"",
                                        ""issuetype"": {""name"": ""Task""}
                                        }
                        }";

        string postUrl = "https://url.com/rest/api/2/issue/createmeta";
        System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
        client.BaseAddress = new System.Uri(postUrl);
        byte[] cred = UTF8Encoding.UTF8.GetBytes("username:pwd");
        client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(cred));
        client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

        var content = new StringContent(data, Encoding.UTF8, "application/json");
        System.Net.Http.HttpResponseMessage response = client.PostAsync("issue", content).Result;
        if (response.IsSuccessStatusCode)
        {
            string result = response.Content.ReadAsStringAsync().Result;
            return result;
        }
        else
        {
            return response.StatusCode.ToString();
        }
    }
}

查看您的代碼,這是我發現的:

  • postUrl變量值更改為https://url.com/rest/api/2/issue
  • client.PostAsync調用中的requestUri參數更改為createmeta

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM