473,465 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Another question regarding HTTPWebRequest

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
3 2766
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nick Jacobsen | last post by:
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...
0
by: someone | last post by:
I am in a situation where I need to package some information from Page1, submit it via POST to another server which will process the information and then send the user to another page on my server...
0
by: Rafael Zavulunov | last post by:
Here's my question: Our company has several web-apps and we're trying to create a central login page as a separate web-app, which will then, based on the user's selection, redirect the user to...
16
by: thomas peter | last post by:
I am building a precache engine... one that request over 100 pages on an remote server to cache them remotely... can i use the HttpWebRequest and WebResponse classes for this? or must i use the...
0
by: R Reyes | last post by:
Another error. I had my friend set up another server at his place and i receieved this error. I think this means that the PUT/POST method was not allowed or permissable on his side right? File...
2
by: Rafael Zavulunov | last post by:
Here's my question: Our company has several web-apps and we're trying to create a central login page as a separate web-app, which will then, based on the user's selection, redirect the user to...
6
by: someone | last post by:
I am in a situation where I need to package some information from Page1, submit it via POST to another server which will process the information and then send the user to another page on my server...
9
by: Denise | last post by:
I have posted a similar message in 2 other forums but got no response. I have spent more hours than I can count researching this. Can anyone provide some insight...? Our ASP.Net application...
8
by: genojoe | last post by:
I am looking for a VB.NET code that I can use to monitor an independent Web Site, I would like to do an equivalent of a PING of the site every 5 minutes or so and make sure that it returns the...
1
by: sindhurasingeetham | last post by:
Hi, I'm new to coding in .NET. I am trying to do an asynchronous call in my code using httpwebrequest. This code works perfectly fine on one server, but does not work on another. The main flow...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.