HttpWebRequest.GetRequestStream() breaks by timeout on SSL connection under Windows 7/Vista

送分小仙女□ 提交于 2019-12-04 01:39:31

This error cropped up in a working C# application after migrating the website being accessed to a new server, and that indicated a server-side problem. Indeed, we finally resolved this issue by setting the "ServerName" value in the Apache configuration file to match the domain name registered in the certificate. (Another forum mentioned that setting "ServerAlias" would also work.)

More specifically, the httpd.conf file for the SSL site had the following in the VirtualHost section:

ServerName www.secure.mydomain.com

The certificate was registered to secure.mydomain.com, and the URL we were accessing was also https://secure.mydomain.com/test.html.

So simply changing the conf file to the following and restarting Apache did the trick:

ServerName secure.mydomain.com

The following would have also worked, most likely:

ServerName www.secure.mydomain.com
ServerAlias secure.mydomain.com

Here's some additional background information, for future reference:

The two errors we saw in the System.Net.trace.log were:

System.Net.Sockets Error: 0 : [4316] Exception in the 
    Socket#18796293::Receive - A blocking operation was 
    interrupted by a call to WSACancelBlockingCall
System.Net Error: 0 : [4316] Exception in the 
    HttpWebRequest#35191196:: - The operation has timed out

Here are all the things we tried which did not resolve the issue:

  • installing intermediate certificates from the SSL certificate issuer into Apache (this is required)
  • changing user agent in web request (no effect)
  • changing server-side and client-side time-outs and memory limits (no effect)
  • testing with a static page (no effect)
  • testing with other https sites (they worked fine)
  • adding the cert to the trusted certificates store (no effect)
  • purchase and install a certificate from a different certificate issuer (no effect)
  • compare virtual host .conf files from a known working server to the problem server (this led us to resolve the issue)

The https URL could be opened in Opera, IE8, and Firefox without any problems. WGET for Windows complained about an invalid certificate, but then again, WGET is an old application and does not appear to trust as many certificates.

The C# client application worked under Windows XP, but not in Windows 7 or Windows Vista. It appears that Windows 7 and Vista are more aggressive about validating the certificate. They do not provide an informative error message when it fails, and instead simply time out during the SSL handshake.

Maybe the SSL certificate refers to a CRL which takes too long to fetch?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!