Advertisement
Shell_Casing

Untitled

Jul 25th, 2019
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using System;
  2. using System.Net;
  3. using System.IO;
  4. using System.Text;
  5. using Newtonsoft.Json;
  6. using Newtonsoft.Json.Linq;
  7. namespace c_examples
  8. {
  9.   class Program
  10.   {
  11.     public const string username = "api-token";
  12.     public const string password = "wu7sglosrwxsq";
  13.     public static String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username+":"+password));
  14.     public static JObject responseToJSON (WebResponse wr)
  15.     {
  16.       var response = (HttpWebResponse)(wr);
  17.       StreamReader sr = new StreamReader(response.GetResponseStream());
  18.       var re = sr.ReadToEnd();
  19.       var dobject = JsonConvert.DeserializeObject(re.ToString());
  20.       var jobj = (JObject) dobject;
  21.       return jobj;
  22.     }
  23.     static void Main(string[] args)
  24.     {
  25.       ServicePointManager.ServerCertificateValidationCallback+= (sender, cert, chain, sslPolicyErrors) =>true;      
  26.      
  27.       var request = (HttpWebRequest) WebRequest.Create("https://dev.azure.com/v-tela/_apis/projects");
  28.       request.Method = "GET";
  29.       request.Headers.Add("Authorization", "Basic "+encoded);
  30.       var response = (HttpWebResponse)request.GetResponse();
  31.       JObject jo = responseToJSON(response);
  32.       Console.WriteLine(jo);
  33.      
  34.     }
  35.   }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement