I'm using the TWebHttpRequest component in TMS WEB Core to do an API call, but I'm not sure how to get the status codes of the response.
This is the current code that I use to do the API call using the TWebHttpRequest component:
procedure SendEmail(Sender, MailSubject, MailBody, recipients, cc: String);
var
Email: TWebHttpRequest;
begin
Email := TWebHttpRequest.Create(nil);
Email.URL := 'MY_ENDPOINT_URL_FOR_SENDING_EMAIL...';
Email.Command := httpPOST;
Email.Headers.Clear;
Email.Headers.AddPair('Content-Type','application/json');
Email.PostData := '{' +
'"Sender": "' + Sender + '",' +
'"MailSubject": "' + MailSubject + '",' +
'"MailBody": "' + MailBody + '",' +
'"recipients": "' + recipients + '",' +
'"cc": "' + cc + '"' +
'}';
Email.Execute(
procedure(AResponse: string; AReq: TJSXMLHttpRequest)
begin
Email.Free;
end
);
end;
What I need is the status and/or error codes on the response (200=ok, 403=forbidden, 404=not_found, etc.)
How can I get the status codes when using TWebHttpRequest?
AResponseonly contains my custom JSON. It doesn't contain the status codes. At least not with my API calls. As an example, myAResponsecontains{"value": "Email Sent"}