简体   繁体   English

RESTSharp的简单cURL请求

[英]simple cURL request with RESTSharp

I want to execute a simple cURL command with c# 我想用C#执行一个简单的cURL命令

curl https://doma.in/to/verify/license \
-d "produkt=test01" \
-d "key=123123123123" \
-X POST

What is what is the equivalent to C# or RESTSharp? 什么是C#或RESTSharp? I tried this: 我尝试了这个:

var client = new RestClient("https://doma.in");
var request = new RestRequest("/to/verify/license", Method.POST);

But I don't know how to translate this to RESTSharp: 但是我不知道如何将其转换为RESTSharp:

-d "produkt=test01" \
-d "key=123123123123" \
-X POST

Manpage of cURL says '-d' is for send data but I can't find a send data tag for RESTSharp. cURL的联机帮助页说“ -d”用于发送数据,但是我找不到RESTSharp的发送数据标签。 How can I translate this code to c#? 如何将此代码转换为C#? And how can I save the answer? 以及如何保存答案?

You can create a model to hold the data to be posted and add it to the request. 您可以创建一个模型来保存要发布的数据,并将其添加到请求中。

//...

var body = new {
    produkt = "test01",
    key = "123123123123"
};

request.AddBody(body);

Check the RestSharp site for documentation on how to use the library 检查RestSharp网站以获取有关如何使用该库的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM