https://github.com/restsharp/RestSharp

postman 生成的访问代码;

好用!

Features

  • Assemblies for .NET 4.5.2 and .NET Standard 2.0
  • Easy installation using NuGet for most .NET flavors (signed)
  • 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, PATCH, HEAD, OPTIONS, DELETE, COPY 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
var client = new RestClient("http://example.com");
// client.Authenticator = new HttpBasicAuthenticator(username, password); var request = new RestRequest("resource/{id}");
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("file", path); // execute the request 执行请求
var response = client.Post(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();
var response2 = client.Post<Person>(request);
var name = response2.Data.Name; // or download and save file to disk
client.DownloadData(request).SaveAs(path); // easy async support
await client.ExecuteTaskAsync(request); // async with deserialization
var asyncHandle = client.PostAsync<Person>(request, response => {
Console.WriteLine(response.Data.Name);
}); // abort the request on demand
asyncHandle.Abort();

最新文章

  1. 【bzoj1004】 HNOI2008—Cards
  2. iOS中的交换空间(swap space)
  3. Hadoop安装指引
  4. uva 11020 - Efficient Solutions ——平衡BST
  5. AP_AP系列 - 相关设定的简述(概念)
  6. ORA-12154 终极解决办法
  7. JQuery事件处理的注意事项
  8. C#中的文件操作2
  9. Rotational Region CNN
  10. SDN资料
  11. HTTP的一些基本概念
  12. Linux内核入门到放弃-网络-《深入Linux内核架构》笔记
  13. SAS 创建新变量
  14. LeetCode(116):填充同一层的兄弟节点
  15. python module install
  16. 《C#从现象到本质》读书笔记(二)第2章 C#类型基础(上)
  17. iOS,Android,WP, .NET通用AES加密算法
  18. C#杂乱知识汇总
  19. Hive use mapreduce引擎 bsonFile splits报错处理
  20. Leetcode题库——16.最接近的三数之和

热门文章

  1. 剑指offer6:旋转数组的最小数字
  2. pip安装源
  3. asp.net练习①——Application聊天室
  4. 【hash】A Horrible Poem
  5. Spring 的 Bean 管理(注解方式)
  6. java----FileInputStream类与FileReader类的区别(转)
  7. sql当前时间往后半年
  8. js多语言切换demo
  9. VMwarevSphere Client 链接 vCenter Server中的主机,开启虚拟机提示:在主机当前连接状况下不允许执行该操作
  10. Java学习笔记【十、泛型】