C\

From , 5 Years ago, written in C#, viewed 72 times.
URL https://pastebin.vip/view/a88aeeec
  1. public static string GetWebPageAsString(string url)
  2. {
  3.     HttpWebRequest httpWebRequest = (HttpWebRequest) WebRequest.Create(url);
  4.     HttpWebResponse httpWebResponse = null;
  5.     string xml = "";
  6.     try
  7.     {
  8.         httpWebResponse = (HttpWebResponse) httpWebRequest.GetResponse();
  9.     }
  10.     catch (WebException exception)
  11.     {
  12.         if (exception.Status == WebExceptionStatus.ProtocolError)
  13.         { //get the response object from the WebException
  14.             httpWebResponse = exception.Response as HttpWebResponse;
  15.             if (httpWebResponse == null){ return "<Error />";}
  16.         }
  17.     }
  18.     Stream stream = httpWebResponse.GetResponseStream();
  19.     StreamReader streamReader = new StreamReader(stream, Encoding.ASCII);
  20.     xml = streamReader.ReadToEnd();
  21.     //streamReader.Close();
  22.     if (httpWebResponse.StatusCode != System.Net.HttpStatusCode.OK)
  23.     {
  24.         throw new Exception(xml);
  25.     }
  26.  
  27.     return xml;
  28. }
  29. //csharp/4826

Reply to "C\"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website