Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | None | 0 0
  1. using System;
  2. using System.Threading.Tasks;
  3. using Flurl.Http;
  4.  
  5. namespace Aegis
  6. {
  7.     static class HttpClientFactory
  8.     {
  9.         /// <summary>
  10.         ///   Reuseable flurl http client.
  11.         /// </summary>
  12.         public static readonly FlurlClient Client = new FlurlClient();
  13.  
  14.         /// <summary>
  15.         ///   Flurl http client headers.
  16.         /// </summary>
  17.         public static IFlurlClient Headers(this IFlurlClient client)
  18.         {
  19.             client.WithHeaders(new {
  20.                 Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
  21.                 Accept_Language = "en-US,en;q=0.8",
  22.                 User_Agent =
  23.                 "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.89 Safari/537.36 OPR/49.0.2725.47"
  24.             });
  25.  
  26.             return client;
  27.         }
  28.  
  29.         /// <summary>
  30.         ///   Async tinychat login post request.
  31.         /// </summary>
  32.         public static async Task<IFlurlRequest> LoginAsync(this IFlurlRequest request, string token)
  33.         {
  34.             await request.PostUrlEncodedAsync(new {
  35.                     login_username = Config.UserName,
  36.                     login_password = Config.UserPass,
  37.                     remember = 1,
  38.                     next = "",
  39.                     _token = "TOKEN"
  40.                 })
  41.                 .ReceiveString();
  42.  
  43.             return request;
  44.         }
  45.     }
  46.  
  47.     static class HttpClient
  48.     {
  49.         /// <summary>
  50.         ///   Tinychat base url.
  51.         /// </summary>
  52.         const string _tinyChatUrl = "https://tinychat.com";
  53.  
  54.         /// <summary>
  55.         ///   Tinychat login request.
  56.         /// </summary>
  57.         public static async Task<bool> LoginRequest()
  58.         {
  59.             try {
  60.                 var client = HttpClientFactory.Client.Headers().EnableCookies();
  61.  
  62.                 var index = await _tinyChatUrl.WithClient(client)
  63.                     .GetStringAsync();
  64.  
  65.                 await _tinyChatUrl.WithClient(client)
  66.                     .AppendPathSegment("login")
  67.                     .LoginAsync("sd");
  68.  
  69.                 return client.Cookies.ContainsKey("pass");
  70.             }
  71.             catch (Exception e) {
  72.                 FluentConsole
  73.                     .White
  74.                     .Text(Info.Time())
  75.                     .Red
  76.                     .Text(e.Message);
  77.  
  78.                 return false;
  79.             }
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement