VB.NET: Read an external url into a string variable.

Posted November 30th, 2012


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

string url = "http://www.translate-this.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();