simple cURL request with RESTSharp

梦想的初衷 提交于 2019-12-13 03:25:35

问题


I want to execute a simple cURL command with c#

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? 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:

-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. How can I translate this code to c#? And how can I save the answer?


回答1:


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



来源:https://stackoverflow.com/questions/52246452/simple-curl-request-with-restsharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!