怎么解决https服务调用超时

 我来答
迪蒙智慧交通
2017-01-16 · 让城市更畅通,让出行更轻松!
迪蒙智慧交通
迪蒙智慧交通(深圳)有限公司,专门从事城市智慧交通整体解决方案的公司;是中国首家提供智慧停车、网约专车、汽车租赁、汽车金融等一站式智慧交通整体解决方案服务商。欢迎来公司考察,期待与您的合作!
向TA提问
展开全部
自己给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(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式