Hi
I'm trying to access a REST API with the following code, but keep getting this response HttpMessageNotReadableError","code":400,"error_message":"Required request body is missing, and I can't work out why.
When I direct the URL to a socket testing program running locally it looks like the connection is being closed before the json data is sent.
Any help or suggestions would be gratefully received.
procedure TForm1.Button2Click(Sender: TObject);
const url = '
https://api.textanywhere.com/API/v1.0/REST/sms';var
postJson: TJSONObject;
responseData: String;
begin
postJson := TJSONObject.Create;
postJson.Add('message_type', 'GP');
postJson.Add('message', 'Test message');
postJson.Add('recipient','[+44]');
postJson.Add('sender', 'XX');
postJson.Add('scheduled_delivery_time', '20211223101010');
postJson.Add('order_id', '12344');
postJson.Add('returnCredits', true);
With TFPHttpClient.Create(Nil) do
try
AddHeader('Content-Type', 'application/json');
AddHeader('Connection', 'Keep-Alive');
AddHeader('user_key',key);
AddHeader('session_key',session);
RequestBody := TStringStream.Create(postJson.AsJSON);
responseData := Post(url);
finally
Free;
end;
memo1.Lines.Add(responseData);
end;