Probably, the most popular REST API client library for .NET
RestSharp是一个REST API的.NET客户端类库,稳定可靠。
我们通常会遇到一些场景:
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);
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