You are not logged in.
Pages: 1
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
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
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
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
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
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.
Offline
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
@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
Pages: 1