Advertisement
Shell_Casing

using what?

Jul 27th, 2019
727
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. public static async void GetProjects()
  2. {
  3.     try
  4.     {
  5.         var personalaccesstoken = "PAT_FROM_WEBSITE";
  6.  
  7.         using (HttpClient client = new HttpClient())
  8.         {
  9.             client.DefaultRequestHeaders.Accept.Add(
  10.                 new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
  11.  
  12.             client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
  13.                 Convert.ToBase64String(
  14.                     System.Text.ASCIIEncoding.ASCII.GetBytes(
  15.                         string.Format("{0}:{1}", "", personalaccesstoken))));
  16.  
  17.             using (HttpResponseMessage response = await client.GetAsync(
  18.                         "https://dev.azure.com/{organization}/_apis/projects"))
  19.             {
  20.                 response.EnsureSuccessStatusCode();
  21.                 string responseBody = await response.Content.ReadAsStringAsync();
  22.                 Console.WriteLine(responseBody);
  23.             }
  24.         }
  25.     }
  26.     catch (Exception ex)
  27.     {
  28.         Console.WriteLine(ex.ToString());
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement