[SOLVED][ASK] LoadFromStream with Synapse + NativeXML has empty result
lazarus / 38-Networking and Web Programming
----------------------------------------------------------------------
Mujie · 2013-09-23 07:38
Good day everyone,
First I've a simple XML data :
Code: [Select]
John
Whatever
Which has been generated by PHP :
Code: [Select]";
echo '
John
'.$inputdata.'
';
break;
default:
die();
break;
}
?>
With Lazarus I try access the data stream with Synapse on my DLL
library codes :
Code: [Select]uses
..., httpsend, synautil, synacode, NativeXml;
....
function getData(myinputdata: string): string; stdcall;
var
Doc: TNativeXml;
URL: string;
Params: string;
Response: TMemoryStream;
begin
try
Doc := TNativeXml.Create(Doc);
Response := TMemoryStream.Create;
URL := 'http://localhost/myapp/?a=getdata';
Params := 'inputdata='+ EncodeURLElement(myinputdata);
if HttpPostURL(URL, Params, Response) then
begin
//Response.SaveToFile('file.txt'); // <=-- WORK FINE
Doc.LoadFromStream(Response); // <=- EMPTY, WHY ?
Doc.XmlFormat := xfReadable;
MessageBox(0,PChar(Response),PChar('Result'),mb_ok); <=- EMPTY
end
else
MessageBox(0,PChar('Can not POST'),PChar('Warning'),mb_ok);
finally
Doc.Free;
Response.Free;
end;
end;
....
AS the result, "file.txt" has correct data fill, but LoadFromStream
has empty. I just want to use Synapse + NativeXML only. Thanks before
for any help
Regards,
M
EDIT: ajust some code.
----------------------------------------------------------------------
Mujie · 2013-09-23 08:14
Sorry, my mistake. I forget add
Code: [Select]Response.Position := 0;
Before
Code: [Select]Doc.LoadFromStream(Response);
Thanks