Posted By

pckujawa on 07/23/09


Tagged

html web


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

umang_nine
vali29
emregulcan
uday1302
wraith808


Get HTML from a URI


 / Published in: C#
 

  1. // Taken from C# 3.0 Cookbook
  2. public static string GetHtmlFromUri(string resource)
  3. {
  4. string html = string.Empty;
  5. HttpWebRequest req = (HttpWebRequest)WebRequest.Create(resource);
  6. using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse())
  7. {
  8. bool isSuccess = (int)resp.StatusCode < 299 && (int)resp.StatusCode >= 200;
  9. if (isSuccess)
  10. {
  11. using (StreamReader reader = new StreamReader(resp.GetResponseStream()))
  12. {
  13. html = reader.ReadToEnd();
  14. }
  15. }
  16. }
  17. return html;
  18. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: phbianchi on August 5, 2009

Amazing!

You need to login to post a comment.