Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // from docs.microsoft.com
- using System;
- using System.IO;
- using System.Net;
- namespace AzureDevOpsAPIs
- {
- public class GetProjectsInOrganization
- {
- var devOpsUrl = 'https://dev.azure.com/myOrganization/_apis/projects';
- var tokenName = 'api-token';
- var PAT = 'wu7sglaast68mmq67h2d4uk75srwxsq';
- public static void Main()
- {
- // Create a request for the URL.
- WebRequest request = WebRequest.Create(devOpsUrl);
- request.Method = "GET";
- request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(tokenName:PAT));
- // Get the response.
- WebResponse response = request.GetResponse();
- // Display the status.
- Console.WriteLine(((HttpWebResponse)response).StatusDescription);
- // Get the stream containing content returned by the server.
- // The using block ensures the stream is automatically closed.
- using (Stream dataStream = response.GetResponseStream())
- {
- // Open the stream using a StreamReader for easy access.
- StreamReader reader = new StreamReader(dataStream);
- // Read the content.
- string responseFromServer = reader.ReadToEnd();
- // Display the content.
- Console.WriteLine(responseFromServer);
- }
- // Close the response.
- response.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement