我有一个asp.net 4.0脚本,我写的基本上是从安全站点获取RSS源(我们使用SSO解决方案)。该脚本将正确的凭据发布到表单并收集所有cookie,然后使用这些cookie再次发出请求。我遇到的问题是,当我从服务器请求它时,我收到错误"The remote certificate is invalid according to the validation procedure."
在与我们处理证书的人谈话后,他说这与我们购买的证书类型有关。基本上他告诉我,他无能为力。
我的问题是如何阻止此错误出现并让我的脚本运行?
CookieContainer cookieJar = new CookieContainer();
HttpWebRequest wr = (HttpWebRequest)HttpWebRequest.Create("OURADDRESS");
wr.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 3.5.30729;)";
wr.Method = "POST";
wr.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
wr.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7");
wr.KeepAlive = true;
wr.Headers.Add("Keep-Alive: 300");
wr.AllowAutoRedirect = false;
wr.ContentType = "application/x-www-form-urlencoded";
wr.CookieContainer = cookieJar;
StreamWriter sw = new StreamWriter(wr.GetRequestStream());
sw.Write("USER=" + UserName + "&PASSWORD=" + Password);
sw.Close();
HttpWebResponse response = (HttpWebResponse)wr.GetResponse();
foreach (Cookie cookie in response.Cookies)
{
cookieJar.Add(new Cookie(cookie.Name.Trim(), cookie.Value.Trim(), cookie.Path, cookie.Domain));
}
HttpWebRequest request2 = (HttpWebRequest)HttpWebRequest.Create(RssFeedLink);
request2.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 3.5.30729;)";
request2.Method = "GET";
request2.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
request2.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7");
request2.KeepAlive = true;
request2.Headers.Add("Keep-Alive: 300");
request2.CookieContainer = cookieJar;
request2.ContentType = "text/html";
HttpWebResponse response2 = (HttpWebResponse)request2.GetResponse();
StreamReader reader2 = new StreamReader(response2.GetResponseStream());
答案 0 :(得分:0)
我在SO的其他地方遇到了这个问题("The remote certificate is invalid according to the validation procedure." using Gmail SMTP server)。但是,解决方案也适用于此:
ServicePointManager.ServerCertificateValidationCallback = (s, certificate, chain, errs) => true;