1

Is there a way to render a page with a specific culture using System.Net.WebClient?

For example:

System.Net.WebClient client = new System.Net.WebClient();

CultureInfo myCulture = System.Globalization.CultureInfo.GetCultureInfo("es-ES");
// Do something to specify the culture info

client.DownloadString(someUrl);
bubbassauro
  • 3,421
  • 2
  • 45
  • 44

1 Answers1

6

All that the WebClient class does is to perform an HTTP request and read/parse the response. When sending this request you could set headers such as Accept-Language using the Headers property:

client.Headers["Accept-Language"] = "es-ES";

If you are talking about the encoding, when you use the DownloadString method it will look for the response headers in order to use the proper encoding and if the server sends wrong response header you might have encoding problems. If this is the case you could use the DownloadData method which will return you the response as a byte array and you could apply the proper encoding when converting this array to string.

Darin Dimitrov
  • 994,864
  • 265
  • 3,241
  • 2,902
  • WebClient wc = new WebClient(); wc.Headers.Add("Accept-Language", "en-uk,uk;q=0.8,en-us;q=0.5,en;q=0.3"); Works for me – S G Nov 18 '17 at 02:19