JIRA Rest API 405拒绝C#

hlh3406

我正在尝试通过C#使用REST API在JIRA Server实例中创建问题。

我可以使用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();
        }
    }
}
阿尔贝托·埃斯特雷拉(Alberto Estrella)

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

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章