使用RESTSharp的简单cURL请求 [英] simple cURL request with RESTSharp

查看:124
本文介绍了使用RESTSharp的简单cURL请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用c#执行一个简单的cURL命令

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

什么是C#或RESTSharp的等效物? 我试过了:

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);

但是我不知道如何将其翻译为RESTSharp:

But I don't know how to translate this to RESTSharp:

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

cURL的联机帮助页显示"-d"用于发送数据,但是我找不到RESTSharp的发送数据标签.如何将此代码转换为C#?以及如何保存答案?

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);

检查 RestSharp 网站以获取有关如何使用该库的文档

Check the RestSharp site for documentation on how to use the library

这篇关于使用RESTSharp的简单cURL请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆