#1 2020-02-26 16:21:24

Xantharim
Member
Registered: 2020-02-26
Posts: 2

Need help for post a json in a Body

Hi,
i hope, that it is ok, that i ask this question.

I have a problem. I try to send a JSON in a Body with TRestClient, TRestRequest, TRestResponse and it doesn't work after many day's with try and error.
With the free Rest-Debugger it doesn't work too. But I can send it with Postman.exe.
So i found mORMot Framwork. But it seem's complicated.

The API Description https://github.com/blaulichtSMS/docs/bl … _api_v1.md write:

Encoding: UTF-8
Base-Url: https://api.blaulichtsms.net/blaulicht
Ressource: /api/alarm/v1/scenario/config/list
Content-Typ: application/json
JSON:
{
    "username" : "myUser",
    "password" : "mySuperSecretPwd",
    "customerIds" : ["100027"]
}

cumstomerIds is a List of Strings!
Have anyone a simple Example for me to realise it? The Response is a JSON too.

Georg

I use Embarcadero Radstudio Enterprise 10.3 Rio, the mORNot Framework i full functionally installed... :-)

Last edited by Xantharim (2020-02-27 08:01:12)

Offline

#2 2020-02-26 18:08:03

macfly
Member
From: Brasil
Registered: 2016-08-20
Posts: 374

Re: Need help for post a json in a Body

I believe your question is not directly related to Mormot ...

Do you need a client to make requests?

In any case, the json in example is invalid, it contains an extra comma

Maybe the postman is removing it when posting?

Try with this:

{
    "username" : "myUser",
    "password" : "mySuperSecretPwd",
    "customerIds" : ["100027"]
}

Offline

#3 2020-02-27 07:59:54

Xantharim
Member
Registered: 2020-02-26
Posts: 2

Re: Need help for post a json in a Body

Yes I know, it is correct. With postman.exe have i get a correct answer with the json without the last comma. I need only a simple example, how i can send a POST, with the right type and charset to send the json. In the hole examples of mORMot i didn't find a example for this situation.

Last edited by Xantharim (2020-02-27 08:00:06)

Offline

#4 2020-02-27 10:09:28

Vitaly
Member
From: UAE
Registered: 2017-01-31
Posts: 168
Website

Re: Need help for post a json in a Body

I also doubt that you need mORMot for your task.

But you can look into SynCrtSock unit for various abilities to send an HTTP request. I assume the simplest is HttpPost function (for POST method): https://synopse.info/files/html/api-1.1 … l#HTTPPOST

Offline

#5 2020-02-28 15:46:38

uian2000
Member
Registered: 2014-05-06
Posts: 68

Re: Need help for post a json in a Body

hi, @Xantharim
I've make a sample, which show the same result between IndyHttp and WinHttp(from mORMot->SynCrtSock)

You can check it here.
And the result here

btnWinHttp
{"result":"UNKNOWN_USER","description":"unknown username","customerId":null,"configs":[]}
btnIndy
{"result":"UNKNOWN_USER","description":"unknown username","customerId":null,"configs":[]}

Offline

#6 2020-02-28 22:04:59

macfly
Member
From: Brasil
Registered: 2016-08-20
Posts: 374

Re: Need help for post a json in a Body

Seems that the  TRestClient configures something that is not being accepted by this API and RestDebugger probably uses this component.

In addition to the options mentioned by uian2000, in delphi 10.3 you also have TNetHTTPClient that are working.

Code

Offline

#7 2024-09-09 00:59:03

Antonio
Member
From: Porto Alegre - Brasil
Registered: 2013-03-26
Posts: 24
Website

Re: Need help for post a json in a Body

 TCar = class(TSynAutoCreateFields)
  private
    FCOD_CAR        : RawUTF8;
    FDESCRICAO      : RawUTF8;
 published
    property COD_PRO          :RawUTF8 read FCOD_PRO       write FCOD_PRO;
    property DESCRICAO        :RawUTF8 read FDESCRICAO     write FDESCRICAO;
 end;
 TACar = array of TCar;
  
Function TServer.Teste(const pEmpresa: string; var aCar: TACar):RawJson;
Begin
  result := pEmpresa;
end;
 

Offline

#8 2024-09-09 06:00:37

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,548
Website

Re: Need help for post a json in a Body

@Antonio
I am not sure I understand what you posted.

Note that you have now in mORMot 2 an OpenAPI/Swagger code generator, which creates all the mapping client classes of an existing API.
https://forum.lazarus.freepascal.org/in … ic=68444.0

Offline

Board footer

Powered by FluxBB