Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
Delphi 10.2 Tokyo Professional
|
AW: Curl mit Indy aufrufen
10. Apr 2019, 10:22
Weiß nicht ob es mit dem Hinweis von Schokohase schon klappt, aber in deiner Delphi-Version gibt es auch spezielle REST-Klassen.
Mit folgendem Code:
Delphi-Quellcode:
uses
REST.Client, REST.Types;
procedure TForm2.FormCreate(Sender: TObject);
var client: TRESTClient;
response: TRESTResponse;
request: TRESTRequest;
begin
client := TRESTClient.Create(' https://api.nuki.io/');
try
response := TRESTResponse.Create( nil);
try
request := TRESTRequest.Create( nil);
try
request.Client := client;
request.Response := response;
request.Resource := ' account/user';
request.Method := rmPUT; // <<< Edit: Hatte ich vergessen
request.AddParameter(' Authorization', ' Bearer BeispielToken', TRESTRequestParameterKind.pkHTTPHEADER, [poDoNotEncode]);
request.AddBody(' { "type": 0, "email": "example@bsp.com", "name": "apitest", "language": "de" }', TRESTContentType.ctAPPLICATION_JSON);
request.Execute;
Memo1.Text := response.Content;
Label1.Caption := response.StatusText;
finally
request.Free;
end;
finally
response.Free;
end;
finally
client.Free;
end;
end;
Bekomme ich:
Zitat:
StatusCode: 401 (Unauthorized)
{"detailMessage":"Your access token is not authorized","stackTrace":[],"suppressedExceptions":[]}
Also: Es klappt, aber ich hab natürlich kein gültiges Token.
Michael "Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
Geändert von Neutral General (10. Apr 2019 um 10:59 Uhr)
|