【问题标题】:JIRA Rest API 405 rejection C#JIRA Rest API 405 拒绝 C#
【发布时间】:2021-02-28 12:20:13
【问题描述】:

我正在尝试通过 C# 使用 REST API 在我的 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();
        }
    }
}

【问题讨论】:

  • 我认为 URL 应该是 https://url.com/rest/api/2/issue(不带“/createmeta”),如“使用项目键和字段名称创建问题”部分所述
  • @Xerillio 就是这样!!!我已经瞎了!如果您想将其作为答案,我可以将其标记为正确。谢谢!!!!

标签: c# rest jira jira-rest-api


【解决方案1】:

查看您的代码,这是我发现的:

  • postUrl 变量值更改为https://url.com/rest/api/2/issue
  • client.PostAsync调用中的requestUri参数更改为createmeta

【讨论】:

    猜你喜欢
    • 2017-03-09
    • 1970-01-01
    • 1970-01-01
    • 2012-08-05
    • 1970-01-01
    • 2017-12-29
    • 1970-01-01
    • 2017-03-05
    • 2018-05-07
    相关资源
    最近更新 更多