【发布时间】:2019-04-11 06:22:36
【问题描述】:
我能够很好地使用 Azure Devops RestAPI,但突然代码停止工作(甚至与 Azure Devops 在其文档中提供的相同示例)。
我尝试撤销现有的 PAT 并生成新的 PAT,但仍然无效。
public static async void PrintBuilds()
{
try
{
var personalaccesstoken = "PAT";
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(
System.Text.ASCIIEncoding.ASCII.GetBytes(
string.Format("{0}:{1}", "", personalaccesstoken))));
using (HttpResponseMessage response = client.GetAsync(
"https://dev.azure.com/{Organization}/{Projcet}/_apis/build/builds?api-version=5.0").Result)
{
esponse.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
我希望得到 JSON 输出,但我得到 HTTP 状态 302,即重定向到 visualstudio.com 登录页面 - 这可能表明我的 PAT 有问题...
【问题讨论】:
标签: c# api azure-devops azure-devops-rest-api