0

How can I fix this problem?

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);

I tried some methods to solve the problem but didn't work. For example;

StreamReader gelenBilgi = new StreamReader(cevap.GetResponseStream(), Encoding.GetEncoding("iso-8859-9"));

or

StreamReader gelenBilgi = new StreamReader(cevap.GetResponseStream(), Encoding.GetEncoding("windows-1254"));

or

StreamReader gelenBilgi = new StreamReader(cevap.GetResponseStream(), Encoding.UTF8);
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
B. Ulaş Şenol
  • 91
  • 1
  • 2
  • 8

1 Answers1

2

I was having the same problem. This method helped me solve the Turkish character encoding.

            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);
            }
Eren Peksen
  • 175
  • 2
  • 10
Bora Karaca
  • 436
  • 5
  • 14