I have a url and username and password for an external site. If I get the URL through the browser, an authentication window appears. I give him a username and password, and I can get to the page.
I am trying to do the same with code using the HttpWebRequest object:
var webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.GetResponse() , etc.
This worked before website owners added some protection to the site and provided me with a username and password. WebRequest has a credentials property, which I set as follows:
webRequest.Credentials = new NetworkCredential("username", "password")
I also tried:
webRequest.Credentials = new NetworkCredential("username", "password", "url domain")
this always results in an error:
"The remote server returned an error: (401) Unauthorized."
Am I missing something obvious?
source share