Another question regarding HTTPWebRequest

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nick Jacobsen

    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


  • John Saunders

    #2
    Re: Another question regarding HTTPWebRequest

    "Nick Jacobsen" <njacobsen@pfas tship.com> wrote in message
    news:uGMGpzzYDH A.1900@TK2MSFTN GP10.phx.gbl...[color=blue]
    > I am using HTTPWebRequest to connect to a server which requires
    > authentication, then responds with a 302 redirect message, and redirects[/color]
    to[color=blue]
    > DIFFERANT server, which also requires authentication (the same credentials
    > as the first server). My problem is I can get my client to authenticate[/color]
    to[color=blue]
    > the first server, and redirect to the first server, but then when the[/color]
    second[color=blue]
    > server responds with a 401 authentication required message, HTTPWebRequest
    > does not try to authenticate again... any suggestions?[/color]

    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
    john.saunders@s urfcontrol.com


    Comment

    • feroze

      #3
      Re: Another question regarding HTTPWebRequest

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

      CredentialCache cache = new CredentialCache ();
      cache.Add(new Uri(http://server1/path1), "digest", new
      NetworkCredenti al("user1", "pass1", "dom1"));
      cache.Add(new Uri(http://server2/path2), "digest", new
      NetworkCredenti al("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" <john.saunders@ surfcontrol.com > wrote in message
      news:ebHMf92YDH A.2572@TK2MSFTN GP09.phx.gbl...[color=blue]
      > "Nick Jacobsen" <njacobsen@pfas tship.com> wrote in message
      > news:OszZlO1YDH A.1492@TK2MSFTN GP12.phx.gbl...[color=green]
      > > Yes, that works, but creating a new connection for each redirect[/color]
      > drastically[color=green]
      > > slows things down... I was hoping for either a fix for this, or for[/color][/color]
      this[color=blue]
      > to[color=green]
      > > be confirmed as a bug... or for an explination of the reason it behaves
      > > this way, since IE handles it fine...[/color]
      >
      > 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
      > john.saunders@s urfcontrol.com
      >
      >[/color]


      Comment

      Working...