I am trying the following to get list of projects from "on prem" 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());
}
}
I am using a user name and password which has admin permissions on TFS i am trying to connect.But i get unauthorized access error when i try the above.
>
Make sure you have enabled Basic Auth for your TFS:
Here's a simple app using the Catalog Service. It looks for a file by cycling through all Project Collections and Projects, and finds instances of the file by name. It wouldn't take much to change it for your needs.
}