public Crawler(string username, string password) { _username = username; _password = password; _sessionLogin = new CookieSession(LoginUrlBase); _sessionECampus = new CookieSession(ECampusUrlBase); }
private bool TryAuthenticateToken(string token, out CookieSession data) { if (!_sessions.TryGetValue(token, out var s) || s.Expires <= DateTime.UtcNow) { data = null; return(false); } data = s; return(true); }
public async Task can_receive_cookies() { // endpoint does a redirect, so we need to disable auto-redirect in order to see the cookie in the response var resp = await "https://httpbin.org/cookies/set?z=999".WithAutoRedirect(false).GetAsync(); Assert.AreEqual("999", resp.Cookies.FirstOrDefault(c => c.Name == "z")?.Value); // but using WithCookies we can capture it even with redirects enabled await "https://httpbin.org/cookies/set?z=999".WithCookies(out var cookies).GetAsync(); Assert.AreEqual("999", cookies.FirstOrDefault(c => c.Name == "z")?.Value); // this works with redirects too using (var session = new CookieSession("https://httpbin.org/cookies")) { await session.Request("set?z=999").GetAsync(); Assert.AreEqual("999", session.Cookies.FirstOrDefault(c => c.Name == "z")?.Value); } }
public async Task <System.IO.Stream> GetImageStreamAsync(CookieSession cookieSession, CancellationToken ct) { if (!String.IsNullOrWhiteSpace(CachedImagePath) && !CachedImagePath.Contains("..")) { try { if (System.IO.File.Exists(CachedImagePath)) { return(System.IO.File.OpenRead(CachedImagePath)); } else { Log.Warning("Cannot find cache file: {cacheImagePath}.", CachedImagePath); Log.Warning("Falling back on remote URL."); } } catch (System.IO.FileNotFoundException) { Log.Warning("Cannot find cache file: {cacheImagePath}.", CachedImagePath); Log.Warning("Falling back on remote URL."); } }
public PekaClient(string login, string password) { session = new CookieSession(); this.login = login; this.password = password; }
public static async Task <IFlurlResponse> RedirectWithSession(this Task <IFlurlResponse> response, CookieSession session, int step = 1, string referer = "") { while (true) { var rep = await response; if (step == 0) { return(rep); } var redirectUrl = rep.Headers.GetAll("Location").First(); if (referer != "") { response = session .Request(redirectUrl) .WithFakeAgent() .WithAutoRedirect(false) .WithHeader("referer", referer) .GetAsync(); } else { response = session .Request(redirectUrl) .WithFakeAgent() .WithAutoRedirect(false) .GetAsync(); } step -= 1; } }