Reputation: 41
When I send HTTPWebRequests to certain web sites I get a popup message stating that there us an upspecified Security Risk associated with the site and do I want to continue. The message does not occur until after the HTTPWebRequest has been retrived and stored as a string (ResponseAsString in the code below). The HTTPWebrequest retrieves the text of a webpage which is subsequently converted into an IHTMLDocument2 with the code that follows. The warning occurs on the command -- oDoc.close(); A try-catch block does not yield show an error. Is there any way to suppress this message?
//Creates IHTMLDocument2 frow WebRequest!
private IHTMLDocument2 GetIHTMLDoc2FromString(string ResponseAsString)
{
HTMLDocument ProfileHTML = new HTMLDocument();
IHTMLDocument2 oDoc = (IHTMLDocument2)ProfileHTML;
oDoc.write(ResponseAsString);
oDoc.close();
return oDoc;
}
Upvotes: 1
Views: 226
Reputation: 14585
use this code
public static bool IgnoreInvalidSSL { get; set; }
private static bool ValidateRemoteCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors)
{
if (IgnoreInvalidSSL)
{
return true;
}
else
{
return policyErrors == SslPolicyErrors.None;
}
}
Then on your httprequest use
ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(ValidateRemoteCertificate);
Upvotes: 1