1

我有一个我编写的 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());
4

1 回答 1

0

我在 SO 的其他地方遇到了这个问题(“根据验证程序,远程证书无效。”使用 Gmail SMTP 服务器)。但是,该解决方案也适用于此:

            ServicePointManager.ServerCertificateValidationCallback = (s, certificate, chain, errs) => true;
于 2013-06-25T16:31:21.930 回答