sn_na_v
sn_na_v

Reputation: 31

How to convert the 32 bit webserver to 64 bit response

Already I had a problem with sending data using the TIdHTTP component in Delphi 11, and I got the solution from Getting spaces after upgrading from Indy 9 on Delphi 6 to Indy 10 on Delphi 11.

// sUrl - DSOAP Url
// streamRequest - Request Stream and it will send as compressed data.
// streamResponse - TStream of the response of DSOAP and it will receive as compressed.
IdHttp.Post(sUrl, streamRequest, streamResponse)

Now, I'm facing the problem after receiving the data. How can I read the data from the stream using Delphi 11?

Here is the code to convert the received stream to a string. After calling this method, I'm getting some junk value:

var 
  xml: PChar;
  sXML: string;
  iLength: string;
  streamResponse: TStream; // Before this method, the response is decompressed using ZLib decompression Logic
begin
  iLength := streamResponse.Seek(0, 2);
  xml = strAlloc(iLength+1);
  FillChar(xml^, iLength+1, #0);
  streamResponse.Seek(0, 0);
  streamResponse.Read(xml^, iLength);
  sXML := strPas( xml );   // Getting error after calling this.
  strDispose(xml);
end;

This logic works fine in Delphi 6, but is getting an error while using Delphi 11.

Upvotes: 0

Views: 143

Answers (1)

Oleksandr Morozevych
Oleksandr Morozevych

Reputation: 269

First of all - you must to check if you decompress stream in a right way.

You can do in by saving content of stream in file and open it by any text editor.

streamResponse.SaveToFile('c:\temp\MyStream.txt');

If all is fine - convert it into string:

var
  sStream : TStringStream;
  sXML : string;
...      
  sStream := TStringStream.Create('', TEncoding.UTF8);
  try
    sStream.LoadFromStream(streamResponse);
    sXML := sStream.DataString;
  finally
    sStream.Free
  end;
end;

Upvotes: 1

Related Questions