Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void GetResp()
- {
- string site = "http://tmgwebtest.azurewebsites.net/api/textstrings/1";
- HttpWebRequest req = (HttpWebRequest)WebRequest.Create(site);
- req.Headers.Add("TMG-Api-Key", "0J/RgNC40LLQtdGC0LjQutC4IQ==.");
- HttpWebResponse resp;
- try
- {
- resp = (HttpWebResponse)req.GetResponse();
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- throw;
- }
- Stream receiveStream = resp.GetResponseStream();
- Encoding encoding = Encoding.UTF8;
- StreamReader readStream = new StreamReader(receiveStream ?? throw new InvalidOperationException(), encoding);
- Console.WriteLine("\r\nResponse stream received.");
- char[] bytes = new char[256];
- int count = readStream.Read(bytes, 0, 256);
- Console.WriteLine("HTML...\r\n");
- while (count > 0)
- {
- // Dumps the 256 characters on a string and displays the string to the console.
- String str = new String(bytes, 0, count);
- Console.Write(str);
- count = readStream.Read(bytes, 0, 256);
- }
- Console.WriteLine("");
- // Releases the resources of the response.
- resp.Close();
- // Releases the resources of the Stream.
- readStream.Close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement