Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading.Tasks;
- using Flurl.Http;
- namespace Aegis
- {
- static class HttpClientFactory
- {
- /// <summary>
- /// Reuseable flurl http client.
- /// </summary>
- public static readonly FlurlClient Client = new FlurlClient();
- /// <summary>
- /// Flurl http client headers.
- /// </summary>
- public static IFlurlClient Headers(this IFlurlClient client)
- {
- client.WithHeaders(new {
- Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
- Accept_Language = "en-US,en;q=0.8",
- User_Agent = "Chrome/62.0.3202.89"
- });
- return client;
- }
- /// <summary>
- /// Async tinychat login post request.
- /// </summary>
- public static async Task<IFlurlRequest> LoginAsync(this IFlurlRequest request, string token)
- {
- await request.PostUrlEncodedAsync(new {
- login_username = Config.UserName,
- login_password = Config.UserPass,
- remember = 1,
- next = "",
- _token = "TOKEN"
- })
- .ReceiveString();
- return request;
- }
- }
- static class HttpClient
- {
- /// <summary>
- /// Tinychat base url.
- /// </summary>
- const string _tinyChatUrl = "https://tinychat.com";
- /// <summary>
- /// Tinychat login request.
- /// </summary>
- public static async Task<bool> LoginRequest()
- {
- try {
- var client = HttpClientFactory.Client.Headers().EnableCookies();
- var index = await _tinyChatUrl.WithClient(client)
- .GetStringAsync();
- await _tinyChatUrl.WithClient(client)
- .AppendPathSegment("login")
- .LoginAsync("sd");
- return client.Cookies.ContainsKey("pass");
- }
- catch (Exception e) {
- FluentConsole
- .White
- .Text(Info.Time())
- .Red
- .Text(e.Message);
- return false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement