当前位置: 首页 > 工具软件 > RestSharp > 使用案例 >

RestSharp是什么?

公良浩邈
2023-12-01

RestSharp是什么?

Probably, the most popular REST API client library for .NET

RestSharp是一个REST API的.NET客户端类库,稳定可靠。

我们通常会遇到一些场景:

1、如何调用第三方系统的REST API或WEB API呢?

using RestSharp;
using RestSharp.Authenticators;

var client = new RestClient("https://api.twitter.com/1.1");
client.Authenticator = new HttpBasicAuthenticator("username", "password");

var request = new RestRequest("statuses/home_timeline.json", DataFormat.Json);

var response = client.Get(request);

2、如何调用.net早起版本WebService.asmx?

var client = new RestClient(icURL);
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "text/xml; charset=utf-8;");
request.AddHeader("SOAPAction", "http://tempuri.org/AddXXXXAction");
request.AddParameter("text/xml; charset=utf-8;", postData, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

postData为json字符串

如何安装 RestSharp?

NuGet  

dotnet add package RestSharp

文件为:RestSharp.dll

网站:https://restsharp.dev/

 

 类似资料: