Ok, I just spend a few hours trying to communicate with
this. It seems easy enough:
function TMainForm.Translate(s: string): string;
var
client: TFPHttpClient;
response: TStringStream;
url, r: string;
begin
client := TFPHttpClient.Create(nil);
response := TStringStream.Create('');
url := 'https://libretranslate.com/translate';
r := '{q: "' + s +
'", source: "nl", target: "en", format: "text", api_key: ""}';
client.AddHeader('User-Agent', 'Mozilla/5.0 (compatible; fpweb)');
client.AddHeader('Content-Type', 'application/json');
client.AddHeader('Accept', 'application/json');
client.AllowRedirect := true;
client.RequestBody := TRawByteStringStream.Create(r);
client.Post(url, response);
Result := response.DataString;
client.Free;
response.Free;
end;
Ok, I use:
url := 'http://localhost:5000/translate';
I tried many variations, but none of them work. I always get a 400: BAD REQUEST; '{"error":"The browser (or proxy) sent a request that this server could not understand."}'
It is probably really easy, but I don't get it.