Monday, August 20, 2012

HttpWebRequest Time Out HTTPS Call

I recently had some HttpWebRequest calls begin to timeout without any error code returned. Just a timeout. I had not changed my code so I suspected that the site I was calling had changed something.

I found that I could call other HTTPS sites just fine, but this one in particular just timed out. I also tried to bypass all the certificate errors using the code:

ServicePointManager.ServerCertificateValidationCallback = (s, cert, chain, ssl) => true;

That did not work. I had the break-through moment when I found that if I change the call from HTTPS to HTTP, it worked. Although that was not going to be a fix!

After much searching, I found this post, I submitted the fix to the company and it resolved the problem.

The company had migrated the webserver which was an Apache Server. This small configuration item made some mismatch with the SSL certificate which blocked the HttpWebRequest calls I was making to the HTTPS urls.

Basically, Apache httpd.conf needed to be modified. Here is info from the post:

It had the server name like this: ServerName www.secure.mydomain.com

The certificate was registered to secure.mydomain.com, and the URL I was calling was also https://secure.mydomain.com/xxxx.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

Hope this saves someone a major headache!

1 comment: