Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 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 = "Chrome/62.0.3202.89"
  23.             });
  24.  
  25.             return client;
  26.         }
  27.  
  28.         /// <summary>
  29.         ///   Async tinychat login post request.
  30.         /// </summary>
  31.         public static async Task<IFlurlRequest> LoginAsync(this IFlurlRequest request, string token)
  32.         {
  33.             await request.PostUrlEncodedAsync(new {
  34.                     login_username = Config.UserName,
  35.                     login_password = Config.UserPass,
  36.                     remember = 1,
  37.                     next = "",
  38.                     _token = "TOKEN"
  39.                 })
  40.                 .ReceiveString();
  41.  
  42.             return request;
  43.         }
  44.     }
  45.  
  46.     static class HttpClient
  47.     {
  48.         /// <summary>
  49.         ///   Tinychat base url.
  50.         /// </summary>
  51.         const string _tinyChatUrl = "https://tinychat.com";
  52.  
  53.         /// <summary>
  54.         ///   Tinychat login request.
  55.         /// </summary>
  56.         public static async Task<bool> LoginRequest()
  57.         {
  58.             try {
  59.                 var client = HttpClientFactory.Client.Headers().EnableCookies();
  60.  
  61.                 var index = await _tinyChatUrl.WithClient(client)
  62.                     .GetStringAsync();
  63.  
  64.                 await _tinyChatUrl.WithClient(client)
  65.                     .AppendPathSegment("login")
  66.                     .LoginAsync("sd");
  67.  
  68.                 return client.Cookies.ContainsKey("pass");
  69.             }
  70.             catch (Exception e) {
  71.                 FluentConsole
  72.                     .White
  73.                     .Text(Info.Time())
  74.                     .Red
  75.                     .Text(e.Message);
  76.  
  77.                 return false;
  78.             }
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement