C#HtmlAgilityPack HtmlDocument()LoadHtml编码

mil*_*esh 5 c# encoding

Uri url = new Uri("http://localhost/rgm.php");
WebClient client = new WebClient();
string html = client.DownloadString(url);

HtmlAgilityPack.HtmlDocument doc23 = new HtmlAgilityPack.HtmlDocument();
doc23.LoadHtml(html);

HtmlNode body23 = doc23.DocumentNode.SelectSingleNode("//body");

string content23 = body23.InnerHtml;
Run Code Online (Sandbox Code Playgroud)

如何强制这个用"UTF-8"编码解析网页?

I4V*_*I4V 5

使用DownloadDataWebClient的方法代替DownloadString():

WebClient client = new WebClient();
var data = client.DownloadData(url);
var html = Encoding.UTF8.GetString(data);
Run Code Online (Sandbox Code Playgroud)