c# - 使用 webclient 时出现乱码而不是希伯来语

标签 c# encoding webclient

我正在尝试使用 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/

相关文章:

复制到linux时的PHP编码问题

java - 使用移位操作将 Java 中的代码点转换为 utf-8 字节数组

ruby - 与 ARGF#set_encoding 的混淆

c# - HTTP 范围 : bytes with WebClient C#

html - WebClient.DownloadString 变得乱码

c# - 获取光标相对于控件的位置 - C#

c# - 对象是如何存储在内存中的?

c# - 仅在一台特定机器上的 .NET 应用程序的 SSL 错误 "The message received was unexpected or badly formatted"

c# - 从表达式树中提取所有可能的路径并评估它们是否成立

c# - WebClient 禁止打开维基百科页面?