[英]Get Jira tickets using Jira API and C#
public ActionResult getJiraTickets(string username, string password, string jiraUrl)
{
string queryString = jiraUrl + "/rest/api/2/search";
var client = new HttpClient { BaseAddress = new Uri(queryString) };
var credentials = Encoding.ASCII.GetBytes(username + ":" + password);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(credentials));
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.GetAsync(queryString).Result;
if (response.IsSuccessStatusCode)
{
// use response
}
}
I get StatusCode: 401, ReasonPhrase: 'Unauthorized' in the response. 我在响应中得到StatusCode:401,ReasonPhrase:“未经授权”。
The queryString is correct because if I hit that URI using the browser I get a JSON response back. queryString是正确的,因为如果我使用浏览器访问该URI,则会收到JSON响应。
Username and password are correct as well. 用户名和密码也正确。
What am I doing wrong in the code? 我在代码中做错了什么?
Thanks 谢谢
I apologise for not posting this as a comment, I don't have enough rep yet to post a comment. 很抱歉没有发布此评论,我没有足够的代表来发表评论。
I know you say your username and password are correct but I would double check them because I have taken your code and run it with my login details and Jira Url and it worked as expected. 我知道您说您的用户名和密码是正确的,但我会再次检查它们,因为我已使用您的代码并使用我的登录详细信息和Jira Url运行了它,并且按预期运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.