使用RestSharp凭据从TFS REST API获取用户配置文件

时间:2018-04-24 15:52:59

标签: rest restsharp azure-devops-rest-api

 var client = new RestClient("https://app.vssps.visualstudio.com/_apis/profile/profiles/me?api-version=1.0");
 var request = new RestRequest(Method.GET);
 var authenHeader = new AuthenticationHeaderValue("Bearer",
                    Convert.ToBase64String(
                    System.Text.ASCIIEncoding.ASCII.GetBytes(
                    string.Format("{0}:{1}", username, password))));
 request.AddHeader("Authorization", authenHeader.ToString());
 request.AddHeader("Accept", "application/json");
 IRestResponse response = client.Execute(request);

回应:

StatusCode: NonAuthoritativeInformation, 
Content-Type: text/html; 
.
.

或者此请求只能使用个人访问令牌来获取它?

1 个答案:

答案 0 :(得分:0)

您必须将OAuth与配置文件API一起使用,它不支持基本身份验证。

enter image description here