[SOLVED] LNET HTTPClient - how to POST XML
lazarus / 38-Networking and Web Programming
----------------------------------------------------------------------
Dibo · 2010-07-28 20:43
Hi,
I can't find any example how to POST some data. In demos is only
simple example how to POST using params
(http//www.somesite.com/php?param1=value1¶m2=value2...). But, how
can I post this XML like in synapse:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i procedure
TForm1.buttAddDocumentClick(Sender: TObject);var aHTTP:
THTTPSend;begin aHTTP := THTTPSend.Create; try
WriteStrToStream(aHTTP.Document, 'Test
documentSome text'); aHTTP.MimeType
:= 'application/xml'; if aHTTP.HTTPMethod('POST',
'http://localhost:3000/documents.xml') then begin
aHTTP.Document.Position := 0;
Memo1.Lines.LoadFromStream(aHTTP.Document); end else
ShowMessage('Can not POST'); finally aHTTP.Free; end;end;
Regards
----------------------------------------------------------------------
Dibo · 2010-10-23 18:45
Ok, I very much needed this solution, so I analyze procedure
TLHTTPClientSocket.SendRequest. By default, http client does not send
absolutely no header (only host), so I sniff what sends synapse and do
this same by AddExtraHeader procedure. XML is just new text block in
document so I add this by AddExtraHeader too. This is solution code
which work, maybe someone need this too:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
DecomposeURL('h t tp://some.host.com/login.xml', sHost, sUrl, sPort);
httpclient.Method := hmPost; httpclient.Port := sPort;
httpclient.Host := sHost; httpclient.URI := sUrl;
httpclient.AddExtraHeader('Keep-Alive: 300');
httpclient.AddExtraHeader('Connection: keep-alive');
httpclient.AddExtraHeader('Content-Length: 111'); // <-XML length
httpclient.AddExtraHeader('Content-Type: application/xml;
charset=utf-8'); httpclient.AddExtraHeader(LineEnding);
httpclient.AddExtraHeader( '' + LineEnding +
''+ LineEnding + 'dibo'+ LineEnding + '' );
httpclient.SendRequest;
LHTTPClient is a very good socket but lacks some basic features
visible for programmer (and PUT, DELETE http methods).
But this is not the end of my problems . There is demo how to
download file, but there is no how to upload . Maybe I'll find a way
...
Regards
----------------------------------------------------------------------
xenblaise · 2010-10-26 05:56
You'll find a way dibo, your good.
This post is helpfull too.