Problem with return of POST using Synapse

Asked

Viewed 87 times

1

I am performing a POST request on Delphi XE7 using Synapse (Synalist). I just took the part where I do the POST method and perform my attempts to convert the result.

Above that I declare properties like useragent, headers and cookies.

The Utf8fileto88591 method I got from this link: Utf8fileto88591

var
  http: THTTPSend;
  stl : TstringList;
  ss  : TStringStream;
begin
  if http.HTTPMethod('POST', edtUrMenu.text) then
  begin
    HTTP.Document.position := 0;
    HTTP.Document.saveToFile('d:\a\a3.txt');

    UTF8FileTo88591('d:\a\a3.txt'); // tentativa 1

    stl.defaultEncoding := TEncoding.UTF8; // tentativa 2
    stl.loadFromStream(http.document);
    stl.saveToFile('D:\a\LoadFromStream.txt');

    // tentativa 3
    try
      ss := TStringStream.Create('', TEncoding.UTF8);
      HTTP.Document.position := 0;
      ss.CopyFrom(HTTP.Document, 0);
      ss.SaveToFile('d:\a\a4.txt');
      showmessage(ss.datastring);
    except
    end;
    ss.free;
  end;
end;

The problem is that the output is encoded to which I could not convert. A part of the output (generated through the HTTP.Document.saveToFile(’d: a A3.txt')) or Pastebin with the full result

‹      í½`I–%&/mÊ{JõJ×àt¡€`$Ø@ìÁˆÍæ’ìiG#)«*ÊeVe]f@Ìí¼÷Þ{ï½÷Þ{ï½÷º;N'÷ßÿ?\fdlöÎJÚÉž!€ªÈ?~|?"~ãäñïúôË“7¿ÏËÓtÞ.ÊôåWOžŸ¤mß½ûÝ{'wï>}ó4ý½¿ýæ‹çéîx'}Sg˦h‹j™•wïž¾ø(ýhÞ¶«Gwï^]]¯î«úâî›WwßÖ.^Ö_·[ïÍñ¬}tô'Ô9¾Lß-ÊeóYÒîÇÀG)µ<ϳYZÌ>ûhÚ–;;¿ÿ·éÏÝŽ·E[æôý-ÑMÞ¦/ò«iµ¤7îÊwy›¥è`;ÿEëâò³~ïí¯Ž·OªÅ*k‹I™”Rû6_¶Ÿ}tvúÙéb]fm~vúð£ônäå“l:Ïémê®"Ôì«Ëj{Š¯ø­²X¾Mçu~þÙGãñÝŸnîN›ænu™×Ó¬iïþô/ZçõõöºÓÇ¥u^~öQÓ^—y3Ïóö£´½^åŸ}ÔæïZ¼X,§åz–7w¿È—ëߟpÉÚ¯Jqk³  þk(DÞfZ«ÖÿËL>ŧô\feY]½È/ˆÒ—
  • If you are using XE7 why not use the Indy for this request?

  • I tried with Indy, but I had other problems and I believe it was because of the cookies or the fact that I needed to leave the connection active at any cost (Keep-Alive). I was able to solve the question problem, the content I was receiving was a GZIP, I used a lib to decompress the result.

1 answer

1


I was able to identify the problem and resolve the situation. The content I receive is a gzip, I identified this because in the header I only received a result if I put the following header, without the header or if I accepted another type of encoding I do not receive the content (301 http code):

http.headers.add('Accept-Encoding: gzip, deflate, br');

So I went and found the following library: Gzip to which I used the function unzipStream and then I got the data uncompressed.

ss := TStringStream.create;
b := unzipStream(http.document,ss);
ss.saveToFile('D:\a\a4.txt');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.