I'm trying to log in to a secured web site automatically using c#. To
do this I have go through a proxy server, and use SSL, and log in to
the secure site with another user name and password (different from the
proxy user name and password).
Now, I can get through the proxy by setting the correct credentials on
the WebProxy. I can get through SSL by setting up a dummy certificate
policy class that always returns true. If I go to a regular web site
like http:\\www.google.com it works. If I go to SSL site
(https:\\siteus ingssl.com\) then it works. The problem occurs when
trying to access the site that requires all three methods. The error
returned is 401: Unauthorized. I think the site may use cookies, but I
can't check the cookies returned in the response object because when I
do the request.GetResp onse() it always throws an exception and doesn't
return a valid response object.
If you've read this much, then you deserve to see the code of my most
recent attempt:
//Set Up The Proxy Server
WebProxy proxy = new WebProxy("http://my.proxy.com:31 28/", true);
CredentialCache proxyCache = new CredentialCache () ;
proxyCache.Add( new Uri("http://my.proxy.com:31 28/"), "Basic", new
NetworkCredenti al("user", "pw")) ;
proxyCache.Add( new Uri("https://the.secured.com/"), "Basic", new
NetworkCredenti al("user", "pw")) ;
proxy.Credentia ls = proxyCache ;
request = WebRequest.Crea te("https://the.secured.com ") ;
request.Proxy = proxy;
//Set Up SSL
ServicePointMan ager.Certificat ePolicy = new CertPolicy();
// Send the 'HttpWebRequest ' and wait for response.
HttpWebResponse response = (HttpWebRespons e)request.GetRe sponse();
Any help will be much appreciated.
Thanks,
Brent