Advertisement
Shell_Casing

caller12

Jul 25th, 2019
540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Net.Http;
  7. using System.Net;
  8.  
  9.  
  10. namespace HTTP_Test
  11. {
  12.     class program
  13.     {
  14.         static void Main()
  15.         {
  16.             Task t = new Task(HTTP_GET);
  17.             t.Start();
  18.             Console.ReadLine();
  19.         }
  20.  
  21.         static async void HTTP_GET()
  22.         {
  23.             var TARGETURL = "https://dev.azure.com/myOrganization/_apis/projects";
  24.  
  25.            
  26.             Console.WriteLine("GET: + " + TARGETURL);
  27.  
  28.             // ... Use HttpClient.            
  29.             HttpClient client = new HttpClient();
  30.  
  31.             var byteArray = Encoding.ASCII.GetBytes("api-token:wu7sglofdomcsy4uk75srwxsq");
  32.             client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
  33.  
  34.             HttpResponseMessage response = await client.GetAsync(TARGETURL);
  35.             HttpContent content = response.Content;
  36.  
  37.             // ... Check Status Code                                
  38.             Console.WriteLine("Response StatusCode: " + (int)response.StatusCode);
  39.  
  40.             // ... Read the string.
  41.             string result = await content.ReadAsStringAsync();
  42.  
  43.             // ... Display the result.
  44.             if (result != null &&
  45.             result.Length >= 50)
  46.             {
  47.                 Console.WriteLine(result.Substring(0, 50) + "...");
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement