Donate

Webclient - The remote server returned an error: (403) Forbidden

Using downloadstring of webclient returns an error as stated by the post title. The solution was to add user agent header to the webclient headers. The value of user agent can be found in the mozilla firebug.
Solution:
 string URL = string.Format(your_url);  
  newWebClient.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; rv:2.0)  
                          Gecko/20100101 Firefox/4.0");  
  string pageSource = newWebClient.DownloadString(URL);  
  pageSource = System.Web.HttpUtility.HtmlDecode(pageSource);  

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

Bootstrap Modal In ASP.NET MVC With CRUD Operations