Use HTTPWebRequest to read the contents of a webpage to a string
By [)ia6l0 iii
You can read the contents of a web page into a string using the HTTPWebRequest class
The sample code is as follows:
string pageURL= ""http://www.eggheadcafe.com"";
WebResponse
response = null;
StreamReader reader = null;
HttpWebRequest request
= (HttpWebRequest)WebRequest.Create( pageURL);
request.Method = ""GET"";
response
= request.GetResponse();
reader = new StreamReader( response.GetResponseStream(),
Encoding.UTF8 );
string pageResponse = reader.ReadToEnd();
Related FAQs
You can read the contents of a web page into a string using the WebClient class.
Use the following code snippet to download an image from an URL.
Use the WebClient class from System.Net namespace to download and save a file.
Use the Credentials property of the Http Web Request to specify Credentials.
Use the Proxy property of the Http Web Request to specify proxy.
Use HTTPWebRequest to read the contents of a webpage to a string (2240 Views)