Advertisement
Guest User

RestSharp

a guest
Apr 17th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. using System;
  2. using RestSharp;
  3. namespace ConsoleApplication1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             var client = new RestClient("http://172.18.68.249/api");
  10.             var request = new RestRequest("/login", Method.POST);
  11.             request.AddHeader("Content-Type", "application/json");
  12.             request.RequestFormat = DataFormat.Json;
  13.             request.AddJsonBody(new { UserName = "Administrator", Password = "Welcome01_", Domain = "Test-domain" });
  14.  
  15.             IRestResponse response = client.Execute(request);
  16.             Console.WriteLine((int)response.StatusCode);
  17.  
  18.             var request_list = new RestRequest("/tasks", Method.GET);
  19.             request_list.RequestFormat = DataFormat.Json;
  20.             request_list.AddCookie(".AspNetCore.Cookie", response.Cookies[0].Value);
  21.             IRestResponse response1 = client.Execute(request_list);
  22.             Console.WriteLine((int)response1.StatusCode);
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement