1

I am using the HttpClient class in Windows 8. With Windows Phone, I use the WebClient class in combination with encoding to get the right encoding.

WebClient xml = new WebClient();
xml.Encoding = Encoding.GetEncoding("ISO-8859-1");

In Windows 8 it is looks like this:

HttpClient xml = new HttpClient();
HttpResponseMessage response = await xml.GetAsync(uri);                    
responsetext = await response.Content.ReadAsStringAsync();

How can I add a encoding to support German (umlaute)?

2 Answers 2

2

I don't have time to test right now, but have you tried using the HttpContent.ReadAsByteArrayAsync method (rather than ReadAsStringAsync) and encoding the resulting byte[] into ISO-8859-1 separately?

Sign up to request clarification or add additional context in comments.

Comments

1

Change ReadAsStringAsync to ReadAsBufferAsync and parse result with required encoding

var buffer = await response.Content.ReadAsBufferAsync();
byte [] rawBytes = new byte[buffer.Length];
using (var reader = DataReader.FromBuffer(buffer))
{
    reader.ReadBytes(rawBytes);
}

var res = Encoding.UTF8.GetString(rawBytes, 0, rawBytes.Length);   

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.