JIRA Rest API 405 拒绝 C#
JIRA Rest API 405 rejection C#
我正在尝试通过 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();
}
}
}
查看您的代码,我发现了以下内容:
- 将
postUrl
变量值更改为 https://url.com/rest/api/2/issue
。
- 将
client.PostAsync
调用中的 requestUri
参数更改为 createmeta
。
我正在尝试通过 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();
}
}
}
查看您的代码,我发现了以下内容:
- 将
postUrl
变量值更改为https://url.com/rest/api/2/issue
。 - 将
client.PostAsync
调用中的requestUri
参数更改为createmeta
。