1

I am working on an App for Windows Mobile. Currently I am trying to get the HTML Source code from a webpage with Windows 1252 Encoding. While running the code below I'm always getting a "System.NotSupportedException". Can anybody help me?

The place it gets called:

private async void b_day1_Click(object sender, RoutedEventArgs e)
{
    int day = 1;
    await GetHTML(day);
}

The method "GetHTML(int day)":

public async System.Threading.Tasks.Task<string> GetHTML(int day)
{
    var client = new HttpClient();
    HttpResponseMessage response;
    if (day == 1)
    {
        response = await client.GetAsync("http://www.fsglb.de/fileadmin/stundenplaene/vplan/1.htm");
        var bytearray = await response.Content.ReadAsByteArrayAsync();
        string final = Encoding.GetEncoding(1252).GetString(bytearray);
        Debug.WriteLine(final);
        return final;
    }
}
4
  • Exactly where do you get this extension (works on my machine...)? Can you split the Encoding.GetEncoding and GetString to separate lines var encoding = Encoding.GetEncoding(1252); string final = encoding.GetString(bytearray); Commented May 29, 2016 at 10:37
  • This code works for me well, possibly the problem is in the code that calls this one, can you share it? Commented May 29, 2016 at 10:37
  • I've edited the post... Commented May 29, 2016 at 10:52
  • Use this Use Encoding.Convert method. msdn.microsoft.com/en-us/library/kdcak6ye.aspx Commented Jun 2, 2016 at 11:42

1 Answer 1

2

I've solved the problem. I had to enable all Encodings with:

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Sign up to request clarification or add additional context in comments.

1 Comment

With .netstandard2.0 (and later) you will have to install the nuget package System.Text.Encoding.CodePages in order to get CodePagesEncodingProvider.Instance.

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.