gpt4 book ai didi

c# - HttpWebRequest 的响应不显示 UTF-8 符号

转载 作者:太空宇宙 更新时间:2023-11-03 18:13:11 24 4
gpt4 key购买 nike

我有从网站获取响应的简单代码,但有一个小问题。我试图从俄罗斯网站和一个我不知道符号的网站获得回复,从其他网站获得正常文本。哪里可能有问题?

回复来自:www.kinopoisk.ru

������ � ����...

回复来自:www.yandex.ru

Греция - Чехия. 1:2...

    HttpWebRequest http = (HttpWebRequest) HttpWebRequest.Create("http://");
http.Timeout = 30000;
http.KeepAlive = true;
http.ContentType = "application/x-www-form-urlencoded";
http.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0";
http.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
http.Proxy = null;

WebResponse response = http.GetResponse();
Stream istream = response.GetResponseStream();
StreamReader reader = new StreamReader(istream);

Response.Write(reader.ReadToEnd());

reader.Close();

最佳答案

kinopoisk.ru 被编码为 WINDOWS-1251(您可以在 Content-Type header 中看到它)。

您需要将 Encoding.GetEncoding(1251) 传递给 StreamReader 以对其进行解码。

关于c# - HttpWebRequest 的响应不显示 UTF-8 符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11003288/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com