Author: waterding | Posted on: 1/8/2009 5:43:46 AM | Views : 295

 How to do authentication when sending a HttpWebRequest?
 I am using the code below the request a page. As the page is password protected, I have to do the authentication when I send the httpwebrequest. How to do that?

1 System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(unescapedUri);
2
3 req.AllowAutoRedirect = true;
4 req.MaximumAutomaticRedirections = 3;
5 req.UserAgent = Preferences.UserAgent; //"Mozilla/6.0 (MSIE 6.0; Windows NT 5.1; Searcharoo.NET; robot)";
6 req.KeepAlive = true;
7 req.Timeout = Preferences.RequestTimeout * 1000; //prefRequestTimeout
8 Go to the complete details ...