uwp&wp8.1 Chinese Web page character garbled characters garbled UTF-8 turn GBK resolution method

Source: Internet
Author: User

UWP methods

  Async voidDownload () {/*New HttpClient*/HttpClient web_=NewHttpClient (); /*download using HttpClient's Getasync method*/            varres =awaitWeb_. Getasync (NewUri ("Http://dzs.qisuu.com/txt/%E6%AD%A6%E9%81%93%E7%B3%BB%E7%BB%9F%E4%B9%8B%E8%8D%89%E6%B0%91%E5%B4%9B%E8%B5%B7.txt")); /*registering the character encoding that the desktop program can use*/Encoding.registerprovider (codepagesencodingprovider.instance); /*Register GBK*/Encoding ENCODINGGBK= Encoding.GetEncoding ("GBK"); /*Conversion Encoding*/Stream Streamtoreader=awaitRes.             Content.readasstreamasync (); /*using a new instance of StreamReader: Stream flow, character encoding*/StreamReader SR=NewStreamReader (STREAMTOREADER,ENCODINGGBK); /*asynchronously reads all characters*/            stringText =awaitSr.                Readtoendasync (); /*Assigning a value to a TextBox control*/T.text+=Text; }

WP8.1 Method:

New HttpClient ();             var await web_. Getasync (Thenew Uri ("http://dzs.qisuu.com/txt/%E6%AD%A6%E9%81%93%E7%B3%BB%E7%BB%9F%E4%B9%8B% E8%8d%89%e6%b0%91%e5%b4%9b%e8%b5%b7.txt"));                        /* Convert characters */            var await Res. Content.readasstringasync ();             = Text;

Above is the workaround. No matter what method you use to read characters, or Web pages. In the UWP, be sure to convert to stream and register GBK, which is read through Steramreader. WP8.1 is relatively simple, both methods (UWP and WP8.1) are available.

uwp&wp8.1 Chinese Web page character garbled characters garbled UTF-8 turn GBK resolution method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.