Another question regarding HTTPWebRequest

N

Nick Jacobsen

I am using HTTPWebRequest to connect to a server which requires
authentication, then responds with a 302 redirect message, and redirects to
DIFFERANT server, which also requires authentication (the same credentials
as the first server). My problem is I can get my client to authenticate to
the first server, and redirect to the first server, but then when the second
server responds with a 401 authentication required message, HTTPWebRequest
does not try to authenticate again... any suggestions?

TIA
Nick Jacobsen
 
J

John Saunders

Nick Jacobsen said:
I am using HTTPWebRequest to connect to a server which requires
authentication, then responds with a 302 redirect message, and redirects to
DIFFERANT server, which also requires authentication (the same credentials
as the first server). My problem is I can get my client to authenticate to
the first server, and redirect to the first server, but then when the second
server responds with a 401 authentication required message, HTTPWebRequest
does not try to authenticate again... any suggestions?

Nick,

My guess is that HttpWebRequest doesn't know it's a different server
returning the 401, so it thinks the authentication failed. Maybe if you turn
off automatic redirections and redirect on your own, the 401 from the second
server will be the only 401 HttpWebRequest sees.
 
F

feroze

Since you have different servers that are requiring same credentials, you
should use the CredentialCache, instead of NetworkCredential on the request.
This is how you do it:

CredentialCache cache = new CredentialCache();
cache.Add(new Uri(http://server1/path1), "digest", new
NetworkCredential("user1", "pass1", "dom1"));
cache.Add(new Uri(http://server2/path2), "digest", new
NetworkCredential("user1", "pass1", "dom1"));
req.Credentials = cache;

Now, the webrequest will know that there is a credential for the second
server, and will use those for the second request. Just change the above
lines to suit your needs.

==========================
This posting is provided as-is. It does not offer any warranties and confers
no rights.
 

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