Sunday, June 1, 2008

A simple way to get a content from an URL over the internet

sometimes we want to get the content over the internet and process the content, here is a super simple method that i discovered.


using System.Net;
using System.IO;

public static string GetWebContentString(string
url)
{
HttpWebRequest httpReq =
(HttpWebRequest)WebRequest.Create(url);
HttpWebResponse httpRes =
(HttpWebResponse)httpReq.GetResponse();
Stream fs =
httpRes.GetResponseStream();
StreamReader sr = new
StreamReader(fs);
return sr.ReadToEnd();
}

No comments: