December 1st, 2009, 06:29 PM
why is use of “new NetworkCredential(username, password)” not working for Basic Authe
I have a website that uses Basic Authentication (username/password).
Why is the following code not working? When I run it the web application takes me to the login controller, whereas I'm expecting that it should already be authenticated given I'm populating the credentials. In other words I'm trying to confirm how, in .NET, I confirm my winforms HttpWebRequest so that it will automate the authentication process. I'm assumeing that NetworkCredential is the .net class that should do this? Or in .NET is there an expectation there is some manual two step process you have to implement yourself?
Here is the code:
// Create a new webrequest to the mentioned URL.
var uri = new Uri("http://10.1.1.102:3000/download/sunset");
var myWebRequest = (HttpWebRequest)WebRequest.Create(uri);
var networkCredential=new NetworkCredential("test", "asdfasdf");
var myWebResponse = (HttpWebResponse)myWebRequest.GetResponse();
Console.Out.WriteLine("STATUS = " + myWebResponse.StatusCode);
var stream = myWebResponse.GetResponseStream();
var reader = new StreamReader(stream);
string text_read = reader.ReadToEnd();
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!