I am trying to get Web Page Contents in Code with C# but its giving me error. Please help me to fix it.
string url = "http://www.abesoft.org/query.asp
searchtype=ANY&
query_param=USDOT&original_query_param=NAME&
query_string=2134430&original_query_string=NATIONAL GRASS LLC";
WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse();
Stream data = response.GetResponseStream();
string html = String.Empty;
using (StreamReader sr = new StreamReader(data))
{
html = sr.ReadToEnd();
}
Error- "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."
You can probably use:
To ignore the certificate errors. Source is this article:
http://www.west-wind.com/weblog/posts/2011/Feb/11/HttpWebRequest-and-Ignoring-SSL-Certificate-Errors
Basically you are just trying to ignore the bad certificate on that site.