Read an external url into a string variable

Submitted by:Tim Kelly

Date added:28 November, 2013

Category:VB.NET

Assigns the contents of a "url" to the string variable "result".

Tags: string variable , external url

Code Snippet:

    string url = "http://www.site.com/page.aspx";
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.Method = "GET";
WebResponse myResponse = myRequest.GetResponse();
StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
string result = sr.ReadToEnd();
sr.Close();
myResponse.Close();
 
 

Comments