Quantcast
Channel: General
Viewing all articles
Browse latest Browse all 7363

Getting Error “The remote server returned an error: (403) Forbidden” when screen scraping using HttpWebRequest.GetResponse()

$
0
0

Hi friends,

            i am using httpwebrequest class to get response from a website. my code working fine in development machine.

           But when i uploaded it to  web hosting server then it return 403 forbidden error.

          i cant debug the code.  any body have any answer. my code as follows

 CookieContainer objContainer = new CookieContainer();

Stream dataStream = null;
StreamReader reader = null;

string strServerResponse = "";

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://www.tdscpc.gov.in/app/login.xhtml");
//-------------------------------------
// request.CookieContainer = objContainer;
request.KeepAlive = false;
request.Method = "GET";

// request.UseDefaultCredentials = true;
// request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;

//request.UserAgent = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17";
request.Accept = "text/html";
//-------------------------------------
if (request.CookieContainer == null)
request.CookieContainer = objContainer;

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
request.CookieContainer.Add(response.Cookies);

dataStream = response.GetResponseStream();
reader = new StreamReader(dataStream);
//--------------------------------------
strServerResponse = reader.ReadToEnd();
//----------------------------------------
reader.Close();
dataStream.Close();
response.Close();
//-----------------------------------
Response.Write(strServerResponse);


Viewing all articles
Browse latest Browse all 7363

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>