如何解决此问题?
string icerik;
WebRequest istek = HttpWebRequest.Create(adres);
istek.Proxy = null;
WebResponse cevap = istek.GetResponse();
CultureInfo tr = new CultureInfo("tr-TR");
StreamReader gelenBilgi = new StreamReader(cevap.GetResponseStream(), Encoding.GetEncoding(tr.TextInfo.ANSICodePage));
icerik = gelenBilgi.ReadToEnd();
htmlDoc.LoadHtml(icerik);
我尝试了一些方法来解决问题,但没有奏效。 例如;
StreamReader gelenBilgi = new StreamReader(cevap.GetResponseStream(), Encoding.GetEncoding("iso-8859-9"));
或
StreamReader gelenBilgi = new StreamReader(cevap.GetResponseStream(), Encoding.GetEncoding("windows-1254"));
或
StreamReader gelenBilgi = new StreamReader(cevap.GetResponseStream(), Encoding.UTF8);
答案 0 :(得分:2)
我遇到了同样的问题。这种方法帮助我解决了土耳其语字符编码。
string content;
using (var sr = new StreamReader(cevap.GetResponseStream()))
{
Encoding iso = Encoding.GetEncoding("iso-8859-9");
Encoding utf8 = Encoding.UTF8;
byte[] utfBytes = utf8.GetBytes(sr.ReadToEnd());
byte[] isoBytes = Encoding.Convert(utf8, iso, utfBytes);
content = iso.GetString(isoBytes);
}