【问题标题】:How to use DeepL API curl command with Indy TidHTTP?如何在 Indy TidHTTP 中使用 DeepL API curl 命令?
【发布时间】:2022-01-26 02:15:21
【问题描述】:

https://www.deepl.com的请求示例:

curl https://api-free.deepl.com/v2/translate \
 -d auth_key=[yourAuthKey] \
 -d "text=Hello world!" \
 -d "target_lang=DE"

示例响应:

{"translations": [{
                   "detected_source_language":"EN",
                   "text":"Hallo Welt!"
                 }]
}

我想使用 Indy 的 TIdHTTP 组件在 Delphi 11 中实现上述示例,但我无法将现有答案转换为对我来说可行的解决方案。

【问题讨论】:

  • 几十年来我一直确信 "Hello, World!" 不应该包含逗号,但今天我学会了otherwise

标签: delphi curl https indy


【解决方案1】:

该 curl 示例的 TIdHTTP 等效项是将包含 name=value 对的 TStrings 对象传递给 TIdHTTP.Post() 方法,例如:

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;

【讨论】:

    猜你喜欢
    • 2017-07-08
    • 2021-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多