Ashkan Mobayen Khiabani
Ashkan Mobayen Khiabani

Reputation: 34180

WebClient.DownloadString doesn't return correct unicode charactes altough its encoding is set to UTF8

WebClient wc = new WebClient();
wc.Encoding= System.Text.Encoding.UTF8;
wc.DownloadStringAsync(new Uri("http://example.com/test.html"));

What am I doing wrong here?

Upvotes: 1

Views: 1092

Answers (2)

Hamed Vahedi
Hamed Vahedi

Reputation: 49

This worked for me:

using (var client = new WebClient())
{
    client.Encoding = System.Text.Encoding.UTF8;
    client.Headers.Add(HttpRequestHeader.AcceptCharset, "UTF-8");
    client.DownloadStringAsync(uri);
    //Do-Something
}

Upvotes: 0

Paul Kershaw
Paul Kershaw

Reputation: 51

Try this?

wc.Headers.Add(HttpRequestHeader.AcceptCharset, "UTF-8");

Upvotes: 1

Related Questions