I'm using the following code on Delphi XE7 to make requests to a REST API. It works well, except for when an error such as Internal Server Error occurs. On this occasion, StatusCode
is 0 (while it should be 500) and Content
only returns response header (while I need response body).
var
RESTClient: TRESTClient;
RESTRequest: TRESTRequest;
begin
try
RESTClient:= TRESTClient.Create('http://blah.example.com');
RESTRequest:= TRESTRequest.Create(nil);
RESTRequest.Method:= TRESTRequestMethod.rmGET;
RESTRequest.Resource:= 'customers';
RESTRequest.Accept:= 'application/json';
RESTRequest.Client:= RESTClient;
RESTRequest.Execute;
finally
RESTClient.Free;
RESTRequest.Free;
end;
Everything looks okay in Fiddler. How can I get actual status code and response body when an error (such as Internal Server Error) happens?