如何使用 TFS REST API 访问团队项目列表或 Git 项目列表 [英] How to access team project list or Git project list using TFS REST API

查看:28
本文介绍了如何使用 TFS REST API 访问团队项目列表或 Git 项目列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以下操作以从本地"TFS 获取项目列表

 private static async void Method(){尝试{使用 (HttpClient 客户端 = 新 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}", "用户名", "密码"))));使用 (HttpResponseMessage 响应 = client.GetAsync(http://test-test-app1:8080/tfs/boc_projects/_apis/projects?api-version=2").结果){response.EnsureSuccessStatusCode();string responseBody = await response.Content.ReadAsStringAsync();Console.WriteLine(responseBody);}}}捕获(异常前){Console.WriteLine(ex.ToString());}}

我使用的用户名和密码在 TFS 上具有管理员权限我正在尝试连接.但是当我尝试上述操作时出现未经授权的访问错误.

解决方案

  1. 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.

    解决方案

    1. The REST API of getting a list of team projects is:

    >

    http://tfsserver:8080/tfs/CollectionName/_apis/projects?api-version=1.0
    

    1. Make sure you have enabled Basic Auth for your TFS:

      • check your IIS to see whether the Basic authentication service role is installed.
      • go to IIS Manager, select Team Foundation Server -- Authentication and disable everything other than Basic Authentication. Then do the same for the tfs node under Team Foundation Server.
      • restart your IIS.

    这篇关于如何使用 TFS REST API 访问团队项目列表或 Git 项目列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆