System.Net.WebException: The remote server returned an error: (403) Forbidden

james

New member
Joined
Nov 28, 2021
Messages
2
Programming Experience
3-5
HI. sir .. Can anyone help me to resolve it ? :ROFLMAO: (C# , HttpWebRequest)

Why can't I crawl the data of this page ?

System.Net.WebException: The remote server returned an error: (403) Forbidden
-------------------------------------

C#:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Referer = "https://read01.com/3Lmex5.html";
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36";
cookieStr = "_ga=GA1.2.157330444.1617373251; app_session=thki1lkcba6o4st5fht40q3hm0; __atssc=google;16; AMP_TOKEN=$NOT_FOUND; _gid=GA1.2.706258968.1638088493; __atuvc=0|44,2|45,19|46,3|47,4|48; __atuvs=61a33f2dc5319cf1003";
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";
request.Headers.Add("Cookie", cookieStr);
request.Method = "get";

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
 
Last edited by a moderator:
Very likely the site needs you to refresh any authentication it needs. It looks like you are passing in a cookie string. Where did you get that? How old is it?

In general, look at the rest of the 403 response you got from the server. Often there are clues there that indicate why it thinks you are not allowed to access the resource.
 
HI. sir .. Can anyone help me to resolve it ? :ROFLMAO: (C# , HttpWebRequest)

Why can't I crawl the data of this page ?

System.Net.WebException: The remote server returned an error: (403) Forbidden
-------------------------------------


HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Referer = "https://read01.com/3Lmex5.html";
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36";
cookieStr = "_ga=GA1.2.157330444.1617373251; app_session=thki1lkcba6o4st5fht40q3hm0; __atssc=google;16; AMP_TOKEN=$NOT_FOUND; _gid=GA1.2.706258968.1638088493; __atuvc=0|44,2|45,19|46,3|47,4|48; __atuvs=61a33f2dc5319cf1003";
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";
request.Headers.Add("Cookie", cookieStr);
request.Method = "get";

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

This website is cloudflare site (CDN) ....
 
If it's truly a CDN that doesn't require authentication/authorization, why do you need to pass in those cookies?

If it's a restricted CDN, then you need to pass in the information needed to authenticate/authorize the access.
 
Last edited:
Also, it's not clear what the value of the url that you are passing in since you don't show us how you initialized the variable.
 

Latest posts

Back
Top Bottom