tags:

views:

427

answers:

1

I'm behind a firewall that asks me to enter credentials before letting me access internet. So my first http request is intercepted and then redirected to a secure server that prompts me to enter my credentials, however the server certificate is not valid and hence, my request.getResponse fails with the exception message: "the underlying connection was closed. Could not establish trust relationship for the SSL/TL secure channel"

WebRequest googleRequest = WebRequest.Create("http://74.125.67.100");
try {WebResponse response = googleRequest.GetResponse();}
catch(WebException ex){System.Console.WriteLine("ex.message");}

Actually what I want is to get the Location header of the response that redirects me, so that I can then establish an ssl connection with the server with invalid certificate. I'll be grateful for suggestions.

+4  A: 

Turn off auto-redirection on the initial request. Then you'll be able to pull out the header and do the redirection manually by making a new request.

HttpWebRequest wr = 
(HttpWebRequest)System.Net.WebRequest.Create("http://www.mySite.com"); 
wr.AllowAutoRedirect = false; 
Justin Grant