使用Indy的IDTCPClient从响应流中获取XML [英] Getting XML from response stream using Indy's IDTCPClient
本文介绍了使用Indy的IDTCPClient从响应流中获取XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个问题直接关系到:
我只需要一个get函数来检索XML
I just need a version of get function to retrieve XML
function TMyConnector.GETXML(aRawHeader: String): String;
使用idHTTP组件,我可以执行以下
Using a idHTTP component, I could do the following
HTTP.Request.ContentType := 'text/xml';
我之后的文件标题如下所示:
The header of the file I am after looks like this:
<?xml version="1.0" encoding="utf-8" ?>
如何使用IDTCPClient组件执行此操作?
How can I do this using the IDTCPClient component?
推荐答案
嗯,事实证明它比想象的容易一些。我只是看了一下GenerateJSON方法,并说OK,我该怎么用这个方法来做XML呢?
hmmmm, turns out it was easier than thought. I simply looked at the GenerateJSON method and said ok, How can I use this method for XML.
然后我将MempryStream转到String并发现此功能
I then googled MempryStream to String and found this function
function StreamToString(aStream: TStream): string;
var
SS: TStringStream;
begin
if aStream <> nil then
begin
SS := TStringStream.Create('');
try
SS.CopyFrom(aStream, 0); // No need to position at 0 nor provide size
Result := SS.DataString;
finally
SS.Free;
end;
end else
begin
Result := '';
end;
end;
Procedure TLtLiveConnector.GenerateXML;
begin
if ResponseStream <> nil then
Begin
ResponseXML_V := StreamToString(ResponseStream);
End;
end;
这篇关于使用Indy的IDTCPClient从响应流中获取XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文