delphi 如何将32位Web服务器转换为64位响应

cgyqldqp  于 2023-08-04  发布在  其他
关注(0)|答案(1)|浏览(132)

我在 Delphi 11中使用TIdHTTP组件发送数据时遇到了问题,我从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)

字符串
现在,我收到数据后面临的问题。如何使用 Delphi 11从流中读取数据?
下面是将接收到的流转换为string的代码。调用这个方法后,我得到了一些垃圾值:

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;


这个逻辑在 Delphi 6中工作正常,但是在使用Delphi 11时出现错误。

cgh8pdjw

cgh8pdjw1#

首先-你必须检查你是否以正确的方式解压缩流。
您可以通过保存文件流的内容,并通过任何文本编辑器打开它。

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

字符串
如果一切正常-转换为字符串:

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

相关问题