Bonjour j'essaie d'appeler un service pour récupérer un Bearer
L'appel dans Postman et dans Powershell fonctionne très bien
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" $headers.Add("Content-Type", "application/json") $body = @" { `"username`" : `"13`", `"password`" : `"*******`" } "@ $response = Invoke-RestMethod 'https://api.ptsrc.adeiz.com/api/authenticate' -Method 'POST' -Headers $headers -Body $body $response | ConvertTo-Json
Quand j'essaie de faire ça dans Delphi j'ai toujours la réponse erreur 415 type de média non pris en charge
RESTDEBUGUEUR me donne ça qui fonctionne
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 procedure TForm5.Button1Click(Sender: TObject); var Ljsonobject:tJsonObject; ltoken:string; Litem:tjsonvalue; begin Ljsonobject:=TJSONObject.Create; Ljsonobject.AddPair('username','13'); Ljsonobject.AddPair('password','******'); // Memo1.lines.add(Ljsonobject.ToJSON); // RESTClient1.BaseURL:='https://api.ptsrc.adeiz.com/api/authenticate'; restclient1.po RESTRequest1.AddBody(Ljsonobject.tojson); RESTRequest1.execute; memo1.lines.add(RESTResponse1.Content); end;
mais je ne comprends pas comment remplir simplement la partie params surtout d'ou sort 'body5E80281D4D8B40AFB2A68221EAB654D9' ??object RESTClient1: TRESTClient
Authenticator = SimpleAuthenticator1
BaseURL = 'https://api.ptsrc.adeiz.com/api/authenticate'
Params = <>
SynchronizedEvents = False
end
object RESTRequest1: TRESTRequest
AssignedValues = [rvConnectTimeout, rvReadTimeout]
Client = RESTClient1
Method = rmPOST
Params = <
item
Kind = pkREQUESTBODY
Name = 'body5E80281D4D8B40AFB2A68221EAB654D9'
Value = '{'#13#10' "username" : "13",'#13#10' "password" : "******"'#13#10'}'
ContentTypeStr = 'application/json'
end>
Response = RESTResponse1
SynchronizedEvents = False
end
object RESTResponse1: TRESTResponse
end
object SimpleAuthenticator1: TSimpleAuthenticator
end
quelqu'un peut il m'aider





Répondre avec citation





Partager