【发布时间】:2022-07-08 01:57:42
【问题描述】:
我正在尝试使用 API,他们给出的示例是 Curl 命令的形式:
curl --location --request POST 'https://dev-api.itranslate.com/translation/v2/' --header 'Authorization: Bearer 603160b7-cee1-4c13-bcd7-37420b55211d' --header 'Content-Type: application/json' --data-raw '{
"source": {"dialect": "en", "text": "Hello World"},
"target": {"dialect": "es"}
}'
我正在尝试使用 RestSharp 复制它。但是,在我能找到的所有 RestSharp 示例中,参数都是整齐的名称-值对。但是在这种情况下,参数是不同的,第一个称为“源”,它由另外两个名称-值对组成。
我试过这样的语法:
request.AddHeader("Authorization", "Bearer 603160b7-cee1-4c13-bcd7-37420b55211d");
request.AddParameter("source", "dialect:'en'");
request.AddParameter("source", "Text:'Hello World'");
request.AddParameter("target", "dialect:'es'");
但是服务器没有响应,我猜是因为它不理解请求。如何将这三个东西(“Source”、“Dialect”和“en”)硬塞到一个名称-值对中?
【问题讨论】: