HTTP Network Programming Issue

B

bd-chan

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
 
F

Feroze [msft]

If I unerstand you correctly, you are saying that you cannot get to a site
which requires Cookie, Authentication and SSL at the same time, while going
through a proxy that also requires authentication.

If so, looking at your code below, I dont see you adding credential to the
HttpWebRequest object. You should set credentials on the HttpWebRequest as
well, otherwise your credentials wont be sent, and hence the request will
get denied with a 401.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top