Advertisement
Shell_Casing

api_caller

Jul 24th, 2019
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1.  
  2. // from docs.microsoft.com
  3.  
  4. using System;  
  5. using System.IO;  
  6. using System.Net;      
  7.  
  8. namespace AzureDevOpsAPIs
  9.  
  10. {
  11.     public class GetProjectsInOrganization
  12.     {
  13.        
  14.         var devOpsUrl = 'https://dev.azure.com/myOrganization/_apis/projects';
  15.         var tokenName = 'api-token';
  16.         var PAT = 'wu7sglaast68mmq67h2d4uk75srwxsq';
  17.  
  18.        
  19.         public static void Main()
  20.         {
  21.             // Create a request for the URL.  
  22.             WebRequest request = WebRequest.Create(devOpsUrl);
  23.             request.Method = "GET";
  24.             request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(tokenName:PAT));
  25.            
  26.             // Get the response.  
  27.             WebResponse response = request.GetResponse();
  28.             // Display the status.  
  29.             Console.WriteLine(((HttpWebResponse)response).StatusDescription);
  30.            
  31.             // Get the stream containing content returned by the server.
  32.             // The using block ensures the stream is automatically closed.
  33.             using (Stream dataStream = response.GetResponseStream())
  34.             {
  35.                 // Open the stream using a StreamReader for easy access.  
  36.                 StreamReader reader = new StreamReader(dataStream);
  37.                 // Read the content.  
  38.                 string responseFromServer = reader.ReadToEnd();
  39.                 // Display the content.  
  40.                 Console.WriteLine(responseFromServer);
  41.             }
  42.            
  43.             // Close the response.  
  44.             response.Close();
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement