HTTP Network Programming Issue



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:\\siteusingssl.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.GetResponse() 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:3128/";, true);
CredentialCache proxyCache = new CredentialCache() ;
proxyCache.Add(new Uri("http://my.proxy.com:3128/";), "Basic", new
NetworkCredential("user", "pw")) ;
proxyCache.Add(new Uri("https://the.secured.com/";), "Basic", new
NetworkCredential("user", "pw")) ;

proxy.Credentials = proxyCache ;
request = WebRequest.Create("https://the.secured.com";) ;
request.Proxy = proxy;

//Set Up SSL
ServicePointManager.CertificatePolicy = new CertPolicy();

// Send the 'HttpWebRequest' and wait for response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Any help will be much appreciated.

Thanks,

Brent

.



Relevant Pages