求高手!! 关于HTTPWebRequest 访问HTTPS的网页 提示错误
因为要POST到https的页面上,但是老提示错误: 请求被中止: 未能创建 SSL/TLS 安全通道。 在网上搜了好多资料,最终修改的代码如下:
private bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}
private void senddate()
{
ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(jrlulr);
CookieContainer CookieJar = new CookieContainer();
myRequest.CookieContainer = CookieJar;
myRequest.Credentials = CredentialCache.DefaultCredentials;
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
myRequest.ClientCertificates.Add(crt);
myRequest.KeepAlive = false;
Stream newStream = myRequest.GetRequestStream();
。。。。
}
在运行到 Stream newStream = myRequest.GetRequestStream(); 就提示错误。
我改了另外一个办法
private void senddate()
{
WebClient wc = new WebClient();
wc.Credentials = CredentialCache.DefaultCredentials;
wc.Headers.Set("User-Agent", "Microsoft Internet Explorer");
Stream resStream = wc.OpenRead(jrlulr + "?" + postData);
StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default);
string content = sr.ReadToEnd();
...
}
也是同样的错误
如果我用IE直接打开网址,首先提示一个证书错误,然後点继续后就可以获得返回。初步判断是证书的问题导致的,想咨询一下有什么办法可以忽略证书的错误? 谢谢高手们的帮忙了!!