Skip to content

Instantly share code, notes, and snippets.

@scorta
Last active December 21, 2015 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scorta/6365851 to your computer and use it in GitHub Desktop.
Save scorta/6365851 to your computer and use it in GitHub Desktop.
private string HtmlSrc(string url)
{
try
{
HttpWebRequest myWebRequest = (HttpWebRequest)WebRequest.Create(url);
myWebRequest.Timeout = 5000; // Set time out
myWebRequest.ReadWriteTimeout = 6000; // Set Read Write time out
myWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1);Accept-Language:vi";
WebResponse myWebResponse = myWebRequest.GetResponse();
Stream ReceiveStream = myWebResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader readStream = new StreamReader(ReceiveStream, encode);
string strResponse = readStream.ReadToEnd();
readStream.Close();
myWebResponse.Close();
return strResponse;
}
catch
{
return "Cannot connect";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment