The following code:
WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
string Url = "http://www.tsetmc.com/t
public class WC : WebClient
{
protected override WebRequest GetWebRequest(Uri url)
{
var request = base.GetWebRequest(url) as HttpWebRequest;
request.AutomaticDecompression = DecompressionMethods.GZip;
return request;
}
}
Usage:
var url = "http://www.tsetmc.com/tsev2/data/instinfodata.aspx?i=59266699437480384&c=64";
var wc = new WC();
wc.Encoding = Encoding.UTF8;
var result = wc.DownloadString(url);
In Linqpad you can run the below code, variation from Webclient. As you can see from the picture, its due to the Gzip compression which browser automatically handles.
async void Main()
{
using (var handler = new HttpClientHandler())
{
handler.AutomaticDecompression = DecompressionMethods.GZip;
using (HttpClient client = new HttpClient(handler))
{
var result = await client.GetStringAsync("http://www.tsetmc.com/tsev2/data/instinfodata.aspx?i=59266699437480384&c=64");
result.Dump();
}
}
}
That's not an encoding problem, i think it relates with compression, gzip in this case. Read Uncompressing gzip response from WebClient. That should fix your problem.