一款 .NET 下的轻量级 REST 和 HTTP API 客户端 - RestSharp
2014-05-12 17:04
537 查看
项目地址:https://github.com/restsharp/RestSharp
Easy installation using NuGet for most .NET flavors
Automatic XML and JSON deserialization
Supports custom serialization and deserialization via ISerializer and IDeserializer
Fuzzy element name matching ('product_id' in XML/JSON will match C# property named 'ProductId')
Automatic detection of type of content returned
GET, POST, PUT, HEAD, OPTIONS, DELETE supported
Other non-standard HTTP methods also supported
oAuth 1, oAuth 2, Basic, NTLM and Parameter-based Authenticators included
Supports custom authentication schemes via IAuthenticator
Multi-part form/file uploads
T4 Helper to generate C# classes from an XML document
示例代码:
可参考网址:
/article/4587292.html
谢谢浏览!
Features
Supports .NET 3.5+, Silverlight 4, Windows Phone 7, Mono, MonoTouch, Mono for Android, Compact Framework 3.5Easy installation using NuGet for most .NET flavors
Automatic XML and JSON deserialization
Supports custom serialization and deserialization via ISerializer and IDeserializer
Fuzzy element name matching ('product_id' in XML/JSON will match C# property named 'ProductId')
Automatic detection of type of content returned
GET, POST, PUT, HEAD, OPTIONS, DELETE supported
Other non-standard HTTP methods also supported
oAuth 1, oAuth 2, Basic, NTLM and Parameter-based Authenticators included
Supports custom authentication schemes via IAuthenticator
Multi-part form/file uploads
T4 Helper to generate C# classes from an XML document
示例代码:
var client = new RestClient("http://example.com"); // client.Authenticator = new HttpBasicAuthenticator(username, password); var request = new RestRequest("resource/{id}", Method.POST); request.AddParameter("name", "value"); // adds to POST or URL querystring based on Method request.AddUrlSegment("id", "123"); // replaces matching token in request.Resource // add parameters for all properties on an object request.AddObject(object); // or just whitelisted properties request.AddObject(object, "PersonId", "Name", ...); // easily add HTTP Headers request.AddHeader("header", "value"); // add files to upload (works with compatible verbs) request.AddFile(path); // execute the request IRestResponse response = client.Execute(request); var content = response.Content; // raw content as string // or automatically deserialize result // return content type is sniffed but can be explicitly set via RestClient.AddHandler(); IRestResponse<Person> response2 = client.Execute<Person>(request); var name = response2.Data.Name; // or download and save file to disk client.DownloadData(request).SaveAs(path); // easy async support client.ExecuteAsync(request, response => { Console.WriteLine(response.Content); }); // async with deserialization var asyncHandle = client.ExecuteAsync<Person>(request, response => { Console.WriteLine(response.Data.Name); }); // abort the request on demand asyncHandle.Abort();
可参考网址:
/article/4587292.html
谢谢浏览!
相关文章推荐
- Labview 基于REST API 实现HTTP客户端
- 命令行web客户端与HTTP REST API调试工具
- 微软随.NET 4.5发布新REST API框架(http://www.infoq.com/cn/news/2012/09/rest-web-api)
- RestSharp .net 轻量级rest客户端
- 基于.Net下整合RestSharp,实现REST服务客户端
- 通过 Jersey Http请求头,Http响应头,客户端 API 调用 REST 风格的 Web 服务
- chrome http请求,测试webapp接口之DHC - REST/HTTP API Client
- restsharp 组件调用返回 gbk 编码的api,中文乱码解决方法。(restsharp response 中文乱码 gbk)
- 为 MySQL 增加 HTTP/REST 客户端:MySQL UDF 函数 mysql-udf-http 1.0 发布
- Jersey客户端API调用REST风格的Web服务
- 通过 Jersey 客户端 API 调用 REST 风格的 Web 服务
- WEBAPI VS WCF微软随.NET 4.5发布新REST API框架
- tigase 启用Http Rest API 问题整理
- ArcGIS客户端开发学习笔记(五)——ArcGIS REST API基础
- ArcGIS客户端开发学习笔记(五)——ArcGIS REST API基础
- ElasticSearch通过Rest Http API完成基本操作
- 通过 Jersey 客户端 API 调用 REST 风格的 Web 服务
- 使用http原生包抓取RestAPI接口内容并解析为实体的示例
- 为 MySQL 增加 HTTP/REST 客户端:MySQL UDF 函数 mysql-udf-http 1.0 发布
- 40 个轻量级 JavaScript 库 (转自:http://blog.csdn.net/comsharp/archive/2009/03/05/3959377.aspx)