如何将此三部分卷曲命令转换为RestSharp?
我正在尝试使用API,而他们给出的示例是以卷曲命令的形式:
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'");
但是服务器没有响应,我认为因为它不了解请求。我如何将这三件事(“源”,“方言”和“ en”)分解为一个名称值对?
I am trying to use an API and the example they have given is in the form of a Curl command:
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"}
}'
I am trying to replicate this using RestSharp. However, in all the examples I can find for RestSharp the parameters are in neat name-value pairs. But in this case the parameters are different, the first one is called "source" and it consists of two further name-value pairs.
I have tried syntax like this:
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'");
But the server doesn't respond, I assume because it doesn't understand the request. How can I shoehorn these three things ("Source", "Dialect" and "en") into one name-value pair?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
curl
请求帖子json对象。但是,您的代码发布了URL编码表格。Your
curl
request posts a JSON object. Your code, however, posts a URL encoded form.