[英]Jira REST API returning HTML
I am trying to access the Jira rest API via C#. 我正在尝试通过C#访问Jira rest API。 For that I am using the
Windows.Web.Http.HttpClient
. 为此,我正在使用
Windows.Web.Http.HttpClient
。 But all I get as a return value is HTML. 但是我作为返回值得到的只是HTML。
I am calling the following URL: https://jira.atlassian.com/rest/api/latest/field/
我正在呼叫以下URL:
https://jira.atlassian.com/rest/api/latest/field/
: https://jira.atlassian.com/rest/api/latest/field/
Little Edit 小编辑
When I call the url from a browser it works fine, just the call from the HttpClient doesn't work. 当我从浏览器中调用url时,它可以正常工作,只是HttpClient的调用不起作用。
Here is my code: 这是我的代码:
public async Task<IRestResponse> Execute(RestRequest request) {
var restResponse = new RestResponse();
var client = new HttpClient();
var req = new HttpRequestMessage(request.Method, new Uri(BaseUrl, UriKind.RelativeOrAbsolute));
foreach (var item in request.headers) {
req.Headers[item.Key] = item.Value;
}
req.Headers.Accept.Add(new HttpMediaTypeWithQualityHeaderValue("application/json"));
if (this.Authenticator != null)
req.Headers["Authorization"] = this.Authenticator.GetHeader();
var res = await client.SendRequestAsync(req);
restResponse.Content = await res.Content.ReadAsStringAsync();
restResponse.StatusCode = res.StatusCode;
restResponse.StatusDescription = res.ReasonPhrase;
if (!res.IsSuccessStatusCode) {
restResponse.ErrorMessage = restResponse.Content;
restResponse.ResponseStatus = ResponseStatus.Error;
} else if (res.StatusCode == HttpStatusCode.RequestTimeout) {
restResponse.ResponseStatus = ResponseStatus.TimedOut;
} else if (res.StatusCode == HttpStatusCode.None) {
restResponse.ResponseStatus = ResponseStatus.None;
} else {
restResponse.ResponseStatus = ResponseStatus.Completed;
}
return restResponse;
}
I just found my problem, I don't add the relative path anywhere. 我只是发现了问题,所以没有在任何地方添加相对路径。 It just calls the BaseUrl meaning https://jira.atlassian.com/ that explains why I get the HTML page.
它只是调用BaseUrl,意思是https://jira.atlassian.com/ ,它解释了为什么获得HTML页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.