简体   繁体   中英

simple cURL request with RESTSharp

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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