Ful*_*Int 1 c# utf-8 httpwebrequest utf8-decode
我有简单的代码来获取网站的响应,但有一个小问题.我试图从俄罗斯网站和一个网站得到回复我不知道的符号和其他我得到正常的文本.哪里可能有问题?
回复: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();
Run Code Online (Sandbox Code Playgroud)
kinopoisk.ru被编码为WINDOWS-1251 (你可以在Content-Type标题中看到这一点).
您需要传递Encoding.GetEncoding(1251)给StreamReader才能对其进行解码.
| 归档时间: |
|
| 查看次数: |
6809 次 |
| 最近记录: |