So setze ich den Http-Header wenn
Indy genutzt wird. Die Angaben in spitzen Klammern sind entsprechend zu ersetzen (UserAgent, Application):
Delphi-Quellcode:
FClient.Request.UserAgent := '<UserAgent>';
FClient.Request.Accept := 'application/<Application>+json';
FClient.HandleRedirects := true;
FClient.Request.CustomHeaders.Clear;
FClient.Request.CustomHeaders.AddValue('Accept-Language','de-DE');
FClient.Request.CustomHeaders.AddValue('authorization', 'Bearer ' + FToken);
FClient.HTTPOptions := FClient.HTTPOptions + [hoWantProtocolErrorContent];
So setze ich den RestClient ein:
Delphi-Quellcode:
FRestClient := TRESTClient.Create(BASEURL);
FRestRequest := TRestRequest.Create(nil);
FRestResponse := TRESTResponse.Create(nil);
FRestRequest.Client := FRestClient;
FRestRequest.Response := FRestResponse;
FRestRequest.HandleRedirects := True;
FRestRequest.Params.Clear;
FRestRequest.Accept := 'application/<application>+json';
FRestRequest.Params.AddHeader('Accept-Language', 'de-DE');
FRestRequest.AddParameter('Authorization', FAuthorization , pkHTTPHEADER, [poDoNotEncode]);
FRestRequest.OnHTTPProtocolError := CatchHttpProtocolError;
Beide Methoden funktionieren mit verschiedenen Ziel-Servern produktiv bei > 1000 Usern.