By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,641 Members | 2,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,641 IT Pros & Developers. It's quick & easy.

Another question regarding HTTPWebRequest

P: n/a
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
Nov 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Nick Jacobsen" <nj*******@pfastship.com> wrote in message
news:uG**************@TK2MSFTNGP10.phx.gbl...
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.
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com
Nov 22 '05 #2

P: n/a
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.
"John Saunders" <jo***********@surfcontrol.com> wrote in message
news:eb**************@TK2MSFTNGP09.phx.gbl...
"Nick Jacobsen" <nj*******@pfastship.com> wrote in message
news:Os**************@TK2MSFTNGP12.phx.gbl...
Yes, that works, but creating a new connection for each redirect drastically
slows things down... I was hoping for either a fix for this, or for

this to
be confirmed as a bug... or for an explination of the reason it behaves
this way, since IE handles it fine...


Wasn't it going to use two connections anyway? One per server?

If it starts using more than the two, please post the info here. It's
looking like I'm going to need to do the same thing soon.
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com

Nov 22 '05 #3

P: n/a
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.
"John Saunders" <jo***********@surfcontrol.com> wrote in message
news:eb**************@TK2MSFTNGP09.phx.gbl...
"Nick Jacobsen" <nj*******@pfastship.com> wrote in message
news:Os**************@TK2MSFTNGP12.phx.gbl...
Yes, that works, but creating a new connection for each redirect drastically
slows things down... I was hoping for either a fix for this, or for

this to
be confirmed as a bug... or for an explination of the reason it behaves
this way, since IE handles it fine...


Wasn't it going to use two connections anyway? One per server?

If it starts using more than the two, please post the info here. It's
looking like I'm going to need to do the same thing soon.
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com

Nov 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.