Fill in the keyword: restsharp, and then click the installation button

The minimum requirement of Framework version should be larger than .NET Framework 4.5.2

So make sure to adjust the target .net framework to 4.5.2 version.

Anthor useful tool for parsing JSON structure.

   1: using Newtonsoft.Json;
   2: using Newtonsoft.Json.Linq;
   3: using RestSharp;
   4: using RestSharp.Authenticators;
   5: using RestSharp.Extensions;
   6: using System.IO;
   7: using System.Net;

Simple Request

   1: static string Login()
   2: {
   3:     //login
   4:     RestClient client = new RestClient("https://www.test.com/api");
   5:     RestRequest request = new RestRequest("/auth/signin", Method.POST);
   6:     request.RequestFormat = DataFormat.Json;
   7:     request.AddBody(new { email = "test@test.com", password = "1234" });
   8:     IRestResponse response = client.Execute(request);
   9:     string content = response.Content;
  10:     Console.WriteLine(content);
  11:     return content;
  12: }
   1: static void Parsing(string content)
   2: {
   3:     string user = JObject.Parse(content)["user"].ToString();
   4:     Console.WriteLine("-------------------");
   5:     Console.WriteLine("## Parsing content with key value: user ##");
   6:     Console.WriteLine(user);
   7:     Console.WriteLine("## Parsing user with key value :user_id ##");
   8:     Console.WriteLine(JObject.Parse(user)["user_id"].ToString());
   9:     Console.WriteLine("-------------------");
  10: }

 

References:

1. RestSharp是.NET简单REST和HTTP API 客户端

2. Postman 功能 - Generate Code Snippet

文章標籤
全站熱搜
創作者介紹
創作者 me1237guy 的頭像
me1237guy

天天向上

me1237guy 發表在 痞客邦 留言(0) 人氣(357)