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

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.