我需要通过 REST 从 Azure Devops 2019 获取用户配置文件图像,但它以“NonAuthoritativeInformation”状态响应。我想知道我是否遗漏了什么或在我的请求标头中添加了任何错误。代码如下:
string url = "https://app.vssps.visualstudio.com/_apis/profile/profiles/{640a73ee-ff0c-45b7-85c2-cd1cd6e3a7cb}/avatar";
WebRequest webRequest = WebRequest.Create(url);
webRequest.ContentType = "application/octet-stream";
webRequest.Method = WebRequestMethods.Http.Get;
webRequest.Credentials = CredentialCache.DefaultNetworkCredentials;
webRequest.PreAuthenticate = true;
webRequest.Headers.Add("Authorization", "Bearer {" + this.mOAuthAccessToken+"}");
using (HttpWebResponse response = webRequest.GetResponse() as HttpWebResponse)
{
if (response.StatusCode == HttpStatusCode.OK)
{
using (Stream responseStream = response.GetResponseStream())
{
var filestreamreader = new StreamReader(responseStream);
string result = filestreamreader.ReadToEnd();
}
}
}