HTTPS请求不成功
自己给HttpWebRequest做了些包装,主要是跟其他服务器接口做交互,使用Https协议,封装的类可以在本地正常运行,但是放到服务器上面之后就请求超时,并且同一个服务器上面的WinForm程序能够正常使用这个类,自己写了一个简单的页面做了下测试,本地也是可以正常运行的,服务器上就请求超时,代码如下
protected void Page_Load(object sender, EventArgs e)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
HttpWebRequest reqs = (HttpWebRequest)HttpWebRequest.Create("https://123.123.....");
string path= Server.MapPath("~/AppConfig/abc.pfx");
X509Certificate cer = new X509Certificate(path, "123");
reqs.ClientCertificates.Add(cer);
HttpWebResponse resp = (HttpWebResponse)reqs.GetResponse();
StreamReader streamReader = new StreamReader(resp.GetResponseStream());
string str = string.Empty;
str = streamReader.ReadToEnd();
Response.Write(str);
}
public static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}
这个是运行的异常
Server Error in '/' Application.
--------------------------------------------
The request was aborted: Could not create SSL/TLS secure channel.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[WebException: The request was aborted: Could not create SSL/TLS secure channel.]
System.Net.HttpWebRequest.GetResponse() +5313085
_Default.Page_Load(Object sender, EventArgs e) +215
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad