1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| function TForm1.Connecter(user,password,compagny:string):string;
var
HttpClient: TfPHttpClient;
Reponse: string;
jsonData:TJsonData;
begin
HttpClient := TfPHttpClient.Create(nil);
HttpClient.AddHeader('Accept','application/json');
HttpClient.AddHeader('Content-Type ','application/json');
HttpClient.RequestBody := TStringStream.Create('{"user": "'+user+'",'+
'"password": "'+password+'",'+
'"company": "'+compagny+'"}');
try
Reponse := HttpClient.Post('https://www.xxx.com/rest/v3/login');
except
on e:exception do
begin
ShowMessage('Exception :'+e.message);
HttpClient.RequestBody.Free;
HttpClient.free;
exit;
end;
end;
jsonData:=GETJSON(Reponse);Connecter:=TJSonObject(jsonData).FindPath('data.token').AsString;
end; |
Partager