【发布时间】:2016-10-04 22:21:18
【问题描述】:
我正在尝试以下从“本地”TFS 获取项目列表
private static async void Method()
{
try
{
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}", "Username", "Password"))));
using (HttpResponseMessage response = client.GetAsync(
"http://test-test-app1:8080/tfs/boc_projects/_apis/projects?api-version=2").Result)
{
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
我使用的用户名和密码在我尝试连接的 TFS 上具有管理员权限。但是当我尝试上述操作时出现未经授权的访问错误。
【问题讨论】:
-
我建议使用目录服务而不是 REST API,因为它不需要管理员访问权限。如果你有兴趣,我有代码。
-
告诉我更多关于目录服务,我不知道
标签: tfs