SoFunction
Updated on 2025-03-07

C# webclient Chinese garbled problem solution

When the webclient calls DownloadData or DownloadString, the data returned by the requested data has garbled code. The solution is as follows:

1. Set the encoding format of the webclient to the target encoding format

Copy the codeThe code is as follows:
WebClient web = new WebClient();//Create a webclient object
= .UTF8;//Define the object language
string returns = ("_http:///data/sk/");//Request resources from a connection

2. Get the data first, then transcode it

Copy the codeThe code is as follows:
WebClient wc = new WebClient();
Byte[] pageData = ("/data/");
string rr = ("utf-8").GetString(pageData);

To sum up, it is still a problem of coding. No matter which method, just set up the encoding.