You are not logged in.
We want to create an application calling an existing web service with https.
The first service call will be authentication, parameters are username and password.
On success, we will get a token that is saved to be used in future calls of other service functions.
Responses will be in JSON.
I'm new to mORMot and not yet especially familiar with all functions and need some help finding the key functions.
I've been searching for a while but not found any that sound's to fit in. I'm sure there is but would be grateful to any help.
Looked at the sample code of "Project06ClientMain" and found "Client := TSQLRestClientURINamedPipe.Create(Model,'RestService');". But this uses NamedPipes and I need https.
Also, it uses "model" and wonder if it necessary to create a TSQLRecord here or if there is possible to pick the items from JSON directly here?
I've made it work already with some Delphi components but are very interested in mORMot and want to use it as much as possible.
Last edited by larand54 (2019-02-04 09:26:10)
Delphi-11, WIN10
Offline
I use TWinHttp that is in unit SynCrtSock.pas. I did make a consumer webservice for SOAP and JSON with SSL support.
Esteban
Offline
I've been very busy this week will still be for a while. After all, I tried to test your suggestion, but I can't make it work. I have no idea how to use this.
I tried this but it won't do a thing.
cl := TWinHttp.Create('localhost', '4430', false);
authResponse := cl.Post('localhost/authenticate/',AuthData,'Key: Content-Type, Value: application/json',true,HDRResponse);
I tried to begin without using https and also on a localhost server to minimize error sources.
I debugged the code and it seems that cl.post won't care about what I did in create.
Any idea of what I missing?
Delphi-11, WIN10
Offline
I think there are some mistakes in your code. Please, see below a https authorization example of the Asana API:
http := TWinHttp.Create('app.asana.com','443',true);
try
Status := http.Request('/api/1.0/tasks',
'POST',0,
FormatUTF8('Authorization: Bearer %',[fPersonalAccessToken]),
VariantSaveJson(Json),
'',ResHeader,ResData);
finally
http.Free;
end;
In case to send a POST request to a http webservice:
http := TWinHttp.Create(HostName,'8888',false);
try
Status := http.Request(FormatUTF8('/things/link/%',[ThingCode]),
'POST',0,
'Content-Type: application/json'+#10+'Accept: application/json',
json,
'',ResHeader,ResData);
finally
http.Free;
end;
Please read the incredible documentation to get further details.
Offline
That made it!
Thanks a lot, both of you.
Now I can get rid of the Indy components that require a lot of bugfixes, I had to do myself, to make https work.
Thanks again.
Delphi-11, WIN10
Offline