This is my lines of code for get content of website:
private string GetContent(string url) {
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
var content = String.Empty;
HttpStatusCode statusCode;
using (var response = request.GetResponse())
using (var stream = response.GetResponseStream())
{
var contentType = response.ContentType;
Encoding encoding = null;
if (contentType != null)
{
var match = Regex.Match(contentType, @"(?<=charset\=).*");
if (match.Success)
encoding = Encoding.GetEncoding(match.ToString());
}
encoding = encoding ?? Encoding.UTF8;
statusCode = ((HttpWebResponse)response).StatusCode;
using (var reader = new StreamReader(stream, encoding))
content = reader.ReadToEnd();
}
return content;
}
I have tried to run this lines of code with link: http://google.com. And It's done. But when I runs with link: http://batdongsan.com.vn/. It doesn't work and display "sorry! something went wrong.". And I don't know why what happened with it. How I can get content of second link?