本文介绍了WebHttpRequest getResponse在第二次通话时超时。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 在第二次通话时获得超时异常。 操作已经超时了 System at System.Net.HttpWebRequest.GetResponse() at cc中的abc.abcCommunications.requestResponse(String sPayload):\ ... \\ \\Communications.cs:第58行位于EZDriver.processQueryData(List`1 olData)的c:\ ... \ CommunicatorWeb \ App_Code \ EZDriver.cs:第272行 (a)具有客户端证书连接的SSL。第一次工作正常。第二次发送请求。请求通过但等待响应。服务器没有看到请求。看起来它在第二次SSL协商期间失败了。我们确实看到请求离开防火墙。我无法在非SSL模式下测试此代码。 (b)在XP机器上正常工作。在2003服务器上不起作用。相同的代码/相同的网络/相同的客户端证书/不同的机器。 (c)没有线程代码存在。 (d)我还将此代码包装在Web服务中。停止响应后,执行IISReset会使调用再次起作用,然后失败。无论我是调用web服务还是直接调用它,都会发生超时。 我怀疑在SSL协商和ServicePointManager第二次SSL缓存期间发生了什么。我有.net网络跟踪,当它在XP框上运行正常并在2003框上失败。 这是我的代码 Stream stm = null; StreamWriter stw = null; HttpWebResponse response = null; HttpWebRequest request = null; try { ///代理是否存在 String s = ConfigurationManager.AppSettings [" commproxy"]; if(s!= null&& s.Trim()。Length!= 0) { WebProxy proxyObject = new WebProxy(s,true); HttpWebRequest.DefaultWebProxy = proxyObject; }Get a timeout exception on the 2nd call. The operation has timed outSystemat System.Net.HttpWebRequest.GetResponse()   at abc.abcCommunications.requestResponse(String sPayload) in C:\...\Communications.cs:line 58   at EZDriver.processQueryData(List`1 olData) in c:\...\CommunicatorWeb\App_Code\EZDriver.cs:line 272 (a) SSL with client certificate connection. Works okay the first time. 2nd time the request is sent. Request goes through but waits for a response. Server does not see the request. It looks like it fails during SSL negotiation the 2nd time around. We do see request leaving our firewall. I cannot test this code in non-SSL mode.(b) Works fine on a XP machine. Does not work on a 2003 server. Same code/same network/same client certificate/different machines.(c) No threading code present.(d) I have also wrapped this code in a webservice. After it stops responding doing a IISReset makes the call work again and fail after that. The timeout occurs whether I call the webservice or calling it directly.My suspicion is that there is something happening during SSL negotiation and SSL caching by ServicePointManager the 2nd time around. I have the .net network trace when it works okay on the XP box and fails on the 2003 box.Here is my code            Stream stm = null;            StreamWriter stw = null;            HttpWebResponse response = null;            HttpWebRequest request = null;            try            {                ///Is Proxy present                String s = ConfigurationManager.AppSettings["commproxy"];                if (s != null && s.Trim().Length != 0)                {                    WebProxy proxyObject = new WebProxy(s, true);                    HttpWebRequest.DefaultWebProxy = proxyObject;                } //指向.cer文件位置。 String certPath = ConfigurationManager.AppSettings [" commcertlocation"]; if(certPath == null || certPath.Trim()。Length == 0) { throw new Exception(& ;未在Configuration")中指定证书; } ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(myCertificateValidation); s = ConfigurationManager.AppSettings [" commurl"]; request =(HttpWebRequest)WebRequest.Create(s); this.AttachClientCertificate(request,certPath); request.Timeout = 1 * 60 * 1000; // 1分钟超时 request.Method =" POST" ;; request.ProtocolVersion = HttpVersion.Version11; request.ContentType = @" Multipart / Related; boundary ="" ABC-XML-DATA"" ;; Type ="" Application / X-ABC-STEKMAR""; request.Headers.Add(" MIME-Version", " 1.0"); request.ContentLength = sPayload.Length; stm = request.GetRequestStream(); stw = new StreamWriter(stm); byte [] bpayload = System。 Text.Encoding.Default.GetBytes(sPayload); stm.Write(bpayload,0,bpayload.Length); response =(HttpWebResponse)request.GetResponse(); ////第二次使用TIMEOUT失败 String sResult = getResponse(response); 返回sResult; } { if(stw!= null) stw.Close(); if(stm!= null)stm.Close(); if(response!= null)response.Close(); if(request!= null)request = null; }推荐答案所以这就是你需要做的...... 你做的在您的帖子中声称您认为这是第二次握手问题。运行Wireshark跟踪并发布结果。我们可以在几秒钟内识别出来。关于网络问题的关键事项之一是"哪一方遇到问题"。这就是跟踪将向您展示的内容。因为HTTP是一个如此简洁的协议,所以如果它是一个协商问题,很容易确定(甚至是HTTP)。 只需寻找... SYN -----> < ---- SYN ACK ACK -----> 对于第一个"会话",您应该看到两次握手一次。第二个是下一个。当然,如果这两个看起来都不错,那么你必须使用不同的方法来查看真正发生的事情。一旦我们到达那里,我们将越过那座桥。So here's what you need to do....You make claims in your post that you believe it to be a handshake issue the second time.   Run a Wireshark trace and post the results.  We can identify that in  matter of seconds.   One of the key things to learn about network issues is "which side is having the problem"  This is what the tracing will show you.  Because HTTP is such a clean protocol it's easy to determine (even HTTPs) if it's a negotiation issue.Simply look for...SYN-----><----SYN ACKACK----->You should see that handshake twice once for the first "session" the next for the second.  Of course if both of these look ok then you have to trace using a different method to see what's really happening.  We'll cross that bridge once we get there. 这篇关于WebHttpRequest getResponse在第二次通话时超时。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-03 20:54