I am using the following code the scrape results from another website which requires a userName and DateofBirth to validate and then return the results. The code works fine in Local PC, but gives error in Production Server . Remote Server returned error:(403) Forbidden .
Please suggest some ways to resolve this.
HttpWebResponse res;
System.IO.StreamReader sr;
System.IO.Stream s;
byte[] b;
string postData="Pass=1&UserName=Bob&Dob=03081982&submit1=Submit";
try{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.xxx.org/Login.asp");
request.Method = "POST";
//request.Accept ="*/*";
request.ContentType = "application/x-www-form-urlencoded";
b = System.Text.Encoding.ASCII.GetBytes(postData);
request.ContentLength = postData.Length;
request.UserAgent ="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)";
CookieContainer cookies = new CookieContainer();
request.CookieContainer = cookies;
s=request.GetRequestStream();
s.Write(b, 0, b.Length);
Encoding enc=System.Text.Encoding.ASCII;
WebResponse response = request.GetResponse();
StreamReader responseStream = new StreamReader(response.GetResponseStream(),enc);
//StreamReader responseStream = new StreamReader(response.GetResponseStream(),enc,true);
string responseHtml = responseStream.ReadToEnd();
int resindex=responseHtml.IndexOf("Registration Number:");
litHTMLfromScrapedPage.Text=responseHtml;
}
catch(Exception ex) {
litHTMLfromScrapedPage.Text=ex.Source + " " + ex.Message ;
}