HttpWebRequest的双向SSL问题
一个网银查询接口,需要双向SSL
相关代码如下
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(strUrl);
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;
myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
Stream newStream = myRequest.GetRequestStream();
在vs的debug环境下一切正常,部署到IIS后,在最后一句抛出异常“请求被中止: 未能创建 SSL/TLS 安全通道。”
找过了相关资料,试过了如下两个方法,都没有用
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;或者SecurityProtocolType.Ssl;