我正在尝试使用webclient从页面获取文本,但阿拉伯语文本无法正常显示。我使用以下url = http://www.elnashra.com/尝试了以下代码:
test1:
WebClient webClient = new WebClient();
Stream s = webClient.OpenRead(urlLink);
StreamReader sr = new StreamReader(s);
test2:
String utf8 = webClient.DownloadString(webClient, url, Encoding.UTF8);
输出:
- Elnashra
答案 0 :(得分:0)
当您在浏览器中打开URL并使用开发人员工具检查响应标头时,您可以看到该页面以Windows-1256编码提供:
Content-Type:text/html;charset=windows-1256
你能试试吗
webClient.DownloadString(webClient, url, Encoding.getEncoding(1256));
答案 1 :(得分:0)
尝试以下操作 - 这适用于我:
string url = String.Format("http://www.example.com);
WebClient webClient = new WebClient();
webClient.Encoding = System.Text.Encoding.GetEncoding(1256);
string result = webClient.DownloadString(url);
答案 2 :(得分:0)
这适用于我,它将DownloadString中的数据作为阿拉伯语文本返回,而不会对阿拉伯语文本进行任何更改
WebClient wclient = new WebClient();
wclient.Encoding = Encoding.UTF8;
string RSSData = (wclient.DownloadString(RSSURL));