Forum > Networking and Web Programming

[SOLVED] LNET HTTPClient - how to POST XML

(1/1)

Dibo:
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&param2=value2...). But, how can I post this XML like in synapse:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.buttAddDocumentClick(Sender: TObject);var  aHTTP: THTTPSend;begin  aHTTP := THTTPSend.Create;  try    WriteStrToStream(aHTTP.Document, '<document><title>Test document</title><body>Some text</body></document>');    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:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  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(    '<?xml version="1.0"?>' + LineEnding +    '<login>'+ LineEnding +      'dibo'+ LineEnding +    '</login>'  );  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 :P . There is demo how to download file, but there is no how to upload :) . Maybe I'll find a way ...

Regards

xenblaise:
You'll find a way dibo, your good. :D
This post is helpfull too.

Navigation

[0] Message Index

Go to full version