https://www.deepl.com/ example request:
curl https://api-free.deepl.com/v2/translate \
-d auth_key=[yourAuthKey] \
-d "text=Hello world!" \
-d "target_lang=DE"
Response example:
{"translations": [{
"detected_source_language":"EN",
"text":"Hallo Welt!"
}]
}
I want to implement the above code in Delphi 11 using Indy TIdHTTP
. I wasn't able to translate the existing answers into a workable solution for me.
CodePudding user response:
The TIdHTTP
equivalent of that curl example is to pass a TStrings
object containing name=value
pairs to the TIdHTTP.Post()
method, eg:
PostData := TStringList.Create;
try
PostData.Add('auth_key=[yourAuthKey]');
PostData.Add('text=Hello, world!');
PostData.Add('target_lang=DE');
Response := IdHTTP.Post('https://api-free.deepl.com/v2/translate', PostData);
finally
PostData.Free;
end;