Question : C# HTTP Request with redirect and authentification

Hi all,

I'm having a problem with one of my HTTP request that requires an authentification. Basically I run the code below and it gaves me a (401) Unauthorized error.  I am sure that my username & password are correct.

I think the problem is coming from the URL I'm calling. This is a CGI script that returns a string of variables and then automatically redirects to another URL with the string of variables in parameter. When debugging my script I noticed that the authentification pops up when the HttpRequest is pointing at the second URL. Both URLs are on the same server (same credentials).

Do I need to resubmit the credential for the redirect? I'm not sure this is the problem but I can't find any other explanation...

Please help! Thanks
Code Snippet:
1:
2:
3:
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(URL);
webRequest.Credentials = new NetworkCredential(UserName, Password);
return (HttpWebResponse)webRequest.GetResponse();

Answer : C# HTTP Request with redirect and authentification

Use this impersonation utility before calling the getResponse() function.
 
C# impresonation utility
 
Random Solutions  
 
programming4us programming4us