ورود

View Full Version : سوال: تغییر فرمت متون فارسی



مهران رسا
جمعه 08 مرداد 1389, 11:58 صبح
سلام . با استفاده از کنترل TIdHTTP سورس یک صفحه html رو به صورت زیر دریافت میکنم :



X: string;
X := TIdHTTP.Get('http://www.p30download.com');
اما در برخی موارد(نه برای همه سایت ها) با وجود اینکه اون صفحه وب utf-8 هم هست ، متون فارسی به شکل زیر دریافت میشند :



http://up.iranblog.com/Files1/0506f333ef8d42319cb6.png

کسی میدونه علت چیه ؟

مهران رسا
جمعه 08 مرداد 1389, 23:33 عصر
جواب رو یافتم . Remy Lebeau ، خدا خیرت بده .



the "charset" attribute is required
in order for Indy to decode the UTF-8 automatically. If the server is
sending an HTML page that specifies the UTF-8 encoding in a <meta> tag
inside the HTML itself, and not in the HTTP headers, then Indy cannot decode
it. If that is the case, then you would have to download the data as a
TStream instead of a String and then decode that manually.



دریافت سورس صفحه و تبدیل آن به UTF-8 از طریق Stream :


S: string;
ReplyData := TStringStream.Create('', CP_UTF8);
try
TIdHTTP.Get('http://www.barnamenevis.org', ReplyData);
S := ReplyData.DataString;
finally
ReplyData.Free;
end;
Memo1.Text := S;