0

I get the html-content and show it in a TextBox, but the "ä" is a <?>. It's like Windows doesn't get the ä...

I get the Htmlcontent like this:

public async Task<string> MakeWebRequest()
{
    HttpClient http = new HttpClient();
    HttpResponseMessage response = await http.GetAsync("***URL***");
    return await response.Content.ReadAsStringAsync();
}

How can I get a match in regex to the ä, which Looks like an "?" ?

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Dieter Müller
  • 111
  • 1
  • 13
  • 1
    check this link: http://stackoverflow.com/questions/22649473/getting-an-utf-8-response-with-httpclient-in-windows-store-apps –  Sep 30 '15 at 14:25
  • 1
    Did you try using your own `StreamReader` on `ReadAsStreamAsync` and setting the encoding of that reader explicitly, eg to UTF8? I once had a similar problem and was able to resolve it this way? – Christoph Sep 30 '15 at 14:25
  • there are several other ways to read html as string take a look on them . http://stackoverflow.com/questions/2625618/c-reading-html-source-of-a-webpage-into-a-string – Jawad Zeb Sep 30 '15 at 14:27

1 Answers1

1

Something in the lines of:

using (var client = Connector.GetHttpClient())
{
    var response = await client.GetByteArrayAsync(url);
    data = Encoding.UTF8.GetString(response);
}
Margus
  • 19,694
  • 14
  • 55
  • 103
  • @DieterMüller You can use "return await Encoding.UTF8.GetString(response.Content.ReadAsStringAsync());", other was just to hint that code could be written better. – Margus Sep 30 '15 at 14:39
  • The "(response.Content.ReadAsStringAsync())" don't work – Dieter Müller Sep 30 '15 at 14:42