RMarK0

Untitled

Jun 16th, 2021
780
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static void GetResp()
  2.         {
  3.             string site = "http://tmgwebtest.azurewebsites.net/api/textstrings/1";
  4.  
  5.             HttpWebRequest req = (HttpWebRequest)WebRequest.Create(site);
  6.             req.Headers.Add("TMG-Api-Key", "0J/RgNC40LLQtdGC0LjQutC4IQ==.");
  7.  
  8.             HttpWebResponse resp;
  9.             try
  10.             {
  11.                 resp = (HttpWebResponse)req.GetResponse();
  12.             }
  13.             catch (Exception e)
  14.             {
  15.                 Console.WriteLine(e);
  16.                 throw;
  17.             }
  18.  
  19.             Stream receiveStream = resp.GetResponseStream();
  20.             Encoding encoding = Encoding.UTF8;
  21.             StreamReader readStream = new StreamReader(receiveStream ?? throw new InvalidOperationException(), encoding);
  22.  
  23.             Console.WriteLine("\r\nResponse stream received.");
  24.             char[] bytes = new char[256];
  25.             int count = readStream.Read(bytes, 0, 256);
  26.             Console.WriteLine("HTML...\r\n");
  27.             while (count > 0)
  28.             {
  29.                 // Dumps the 256 characters on a string and displays the string to the console.
  30.                 String str = new String(bytes, 0, count);
  31.                 Console.Write(str);
  32.                 count = readStream.Read(bytes, 0, 256);
  33.             }
  34.             Console.WriteLine("");
  35.             // Releases the resources of the response.
  36.             resp.Close();
  37.             // Releases the resources of the Stream.
  38.             readStream.Close();
  39.         }
RAW Paste Data