idhttp и проблема с кодировкой ответа - PullRequest
0 голосов
/ 07 сентября 2018

У меня небольшая проблема с TIdHTTP в Indy 10.6.2 и Delphi XE8.

Мне нужно получить заголовки из ответа GET. Я делаю:

Try
  SS := TStringStream.Create('');
  newhttp.Get(link,SS);
  html := SS.datastring;
Except end;
SS.free;

html загружен правильно, но если я пытаюсь прочитать заголовки, символы с акцентом заменяются на ?.

Location := newhttp.Response.RawHeaders.Values['location'];
Location := newhttp.Response.Location;

Оба метода имеют одинаковые ? символы в Location.

Мне нужно получить URL для загрузки с акцентированными символами. Я также попробовал:

newhttp.Response.RawHeaders.SaveToStream(SS);

без успеха.

Мой TIdHTTP был создан с

with newhttp do begin
  AllowCookies := True;
  HandleRedirects := False ;
  ProxyParams.BasicAuthentication := False;
  ProxyParams.ProxyPort := 0;
  RedirectMaximum := 15;
  Request.Accept := 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8';
  Request.AcceptEncoding := 'gzip, deflate';
  Request.AcceptLanguage := 'it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7';
  Request.ContentEncoding := 'UTF-8';  //in test
  Request.CharSet := 'UTF-8'; //   //in test
  Request.AcceptCharSet := 'UTF-8';  ////in test
  response.CharSet := 'UTF-8';   //in test
  Response.ContentEncoding := 'UTF-8';  //in test
  Response.ContentType := 'text/plain';  //in test
  Request.BasicAuthentication := False;
  readtimeout:=60000;
  Request.UserAgent := MyAgent;
  HTTPOptions := [hoForceEncodeParams];
  cookiemanager := MyCookie;
end;

Есть предложения?

...