WebRequest Authentication
Hi
I am try to request a HTML file from a server.
Here is my code
string url = "https://www.server.com";
// Create a new webrequest to the mentioned URL.
WebRequest myWebRequest=WebRequest.Create(url);
// Set 'Preauthenticate' property to true. Credentials will be sent with the request.
myWebRequest.PreAuthenticate=true;
// Create a New 'NetworkCredential' object.
NetworkCredential networkCredential=new NetworkCredential("username","password");
// Associate the 'NetworkCredential' object with the 'WebRequest' object.
myWebRequest.Credentials=networkCredential;
// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse myWebResponse=myWebRequest.GetResponse();
When i execute the above code i get an (401) Unauthorised error.
Can anyone help PLEASE?
|