Reputation: 3896
Trying to read an intranet asp page, to get all the HTML code, as I need to search for stuff within that. I can get outside pages to load the html code into a string but not intranet pages, I get error 401 unauthorized. This works fine for outside pages:
HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create(@"http://site/main.asp");
webreq.Method = "GET";
webreq.Credentials = System.Net.CredentialCache.DefaultCredentials;
WebResponse webres = webreq.GetResponse();
StreamReader sr = new StreamReader(webres.GetResponseStream(), System.Text.Encoding.UTF8);
string s = sr.ReadToEnd();
sr.Close();
webres.Close();
This still does not work (not for intranet site at least) other sites is fine. Can anyone see why?
How to fix that issue?
Upvotes: 0
Views: 126
Reputation: 4296
You need to add credentials to your web client. You are getting a 401 on intranet pages because your web client is not authenticating itself.
Upvotes: 1