我正在尝试使用 WebClient 类来查看希伯来语页面的内容,但得到的是乱码而不是希伯来语。
我的代码是:
using (WebClient webClient = new WebClient())
{
webClient.Headers.Add(HttpRequestHeader.ContentType, "charset=windows-1255");
string page = webClient.DownloadString("http://hebrew-academy.huji.ac.il/Pages/default.aspx");
}
我正确地接收到英文内容,但希伯来语内容是乱码,例如:
<标题> ׳”׳׳§׳“׳׳™׳” ׳׳׳©׳•׳ ׳”׳¢׳'׳¨׳™׳× ג€“׳“׳£ ׳”׳'׳™׳×</title>
有谁知道如何正确获取希伯来文内容?
最佳答案
该页面以 UTF-8 格式传输,因此您应该将其解释为 UTF-8,而不是 Windows-1255。 Do this by setting WebClient.Encoding
to System.Text.Encoding.UTF8
.
关于c# - 使用 webclient 时出现乱码而不是希伯来语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18640191/