Question

Im using the synapse lib and i want to send a String to a PHP Api via http post.

This is my final json string which i want to send via http post to the API.

{"os":"Windows7", "architecture":"64", "date":"20.06.2013", "version": "3.22", "name":"TestVM-PC"}

var sSendString: String;
sSendString := '{"os":"Windows7", "architecture":"64", "date":"20.06.2013", "version": "3.22", "name":"TestVM-PC"}';

I found this sample procedure to post parameters, but i don't know how send now correctly one JSON String (sSendString) to the API.

procedure HTTPPost;
var URL: string;
    Params: string;
    Response: TMemoryStream;

begin
  Response := TMemoryStream.Create;

  try
    URL := 'http://testserver.com/api/add_customer';

    Params := 'parameter1=' + EncodeURLElement('data1') + '&' +
              'parameter2=' + EncodeURLElement('data2');

    if HttpPostURL(URL, Params, Response) then
      Response.SaveToFile('c:\response.txt');

  finally
    Response.Free;
  end;
end;

So can someone help me to fixx my problem and show which lines i have to change to send my json string to the API. Thanks in Advance

Was it helpful?

Solution

I also use synapse in my projects. To be make my work simple and faster with Synapse, I wrote THTTPSendEx class, that gives fast speed of using and minimum of code and more features. Currently it's a beta version.

It's views like Indy.

Create THTTPSendEx class. Create methods OnBeginWork, OnWork, OnWorkEnd from it prototypes(see pas file), and assign it to created class. Thats all what you need to indicate progress of HTTP requests, and just call GET, POST functions of the class. Also class haves very simple, "INDY like's", methods of GET, POST requests with many various input and output data types. Try it.

You can see it at my web-site.

If you have any ideas for this, please write it's as a comment to project page.

Sorry for mistakes in english.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top