/// <summary> /// Downloads the image. /// </summary> /// <param name="downloadPath">The download path.</param> /// <param name="savePath">The save path.</param> /// <param name="addReferer">if set to <c>true</c> [add Referrer].</param> /// <param name="addForumCookie">if set to <c>true</c> [add forum cookie].</param> /// <returns> /// Returns if the Image was downloaded or not /// </returns> protected bool DownloadImageAsync(string downloadPath, string savePath, bool addReferer = false, bool addForumCookie = false) { savePath = Path.Combine(this.SavePath, Utility.RemoveIllegalCharecters(savePath)); if (!Directory.Exists(this.SavePath)) { Directory.CreateDirectory(this.SavePath); } savePath = Utility.GetSuitableName(savePath); ((CacheObject)this.EventTable[this.ImageLinkURL]).FilePath = savePath; if (addReferer) { this.WebClient.Headers.Add($"Referer: {this.ThumbImageURL}"); } if (addForumCookie) { this.WebClient.Headers.Add(HttpRequestHeader.Cookie, CookieManager.GetInstance().GetCookieString()); } Application.DoEvents(); this.WebClient.DownloadFileAsync(new Uri(downloadPath), savePath); return(true); }
/// <summary> /// Does the login. /// </summary> /// <param name="url">The URL.</param> /// <returns> /// Returns value if the Login was successfully /// </returns> public bool DoLogin(string url) { var loginURL = $"{url}login.php"; var postData = "do=login&forceredirect=1&url=%2Fforum%2F&vb_login_md5password=%md5pass%&vb_login_md5password_utf=%md5pass%&s=&vb_login_username=%md5user%&vb_login_password=&cookieuser=1"; postData = postData.Replace("%md5pass%", this._userPassword); postData = postData.Replace("%md5user%", this._userName); var loginSuccessfully = false; try { var cookieContainer = new CookieContainer(); var req = (HttpWebRequest)WebRequest.Create(loginURL); req.CookieContainer = cookieContainer; req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.KeepAlive = true; var encoding = new ASCIIEncoding(); var loginDataBytes = encoding.GetBytes(postData); req.ContentLength = loginDataBytes.Length; var stream = req.GetRequestStream(); stream.Write(loginDataBytes, 0, loginDataBytes.Length); stream.Close(); var res = (HttpWebResponse)req.GetResponse(); res.Cookies = req.CookieContainer.GetCookies(req.RequestUri); var cookieMgr = CookieManager.GetInstance(); foreach (Cookie cook in res.Cookies) { cookieMgr.SetCookie(cook.Name, cook.Value); if (cook.Name.Contains("userid") && !string.IsNullOrEmpty(cook.Value)) { loginSuccessfully = true; } } } catch (Exception ex) { MessageBox.Show($"{ex.Message}\n{ex.StackTrace}"); } return(loginSuccessfully); }
/// <summary> /// Gets the Security Token for the Thank You Button /// </summary> /// <param name="pageUrl">URL of the Post</param> /// <returns>The Security Token</returns> public static string GetSecurityToken(Uri pageUrl) { var webClient = new WebClient(); webClient.Headers.Add($"Referer: {pageUrl}"); if (!CacheController.Instance().UserSettings.GuestMode) { webClient.Headers.Add($"Cookie: {CookieManager.GetInstance().GetCookieString()}"); } return(GetSecurityToken(webClient.DownloadString(pageUrl))); }
/// <summary> /// Gets the forum page as string. /// </summary> /// <param name="url">The URL.</param> /// <returns> /// The Page Content /// </returns> public static string GetForumPageAsString(string url) { string pageContent; try { var webClient = new WebClient(); if (!CacheController.Instance().UserSettings.GuestMode) { webClient.Headers.Add($"Cookie: {CookieManager.GetInstance().GetCookieString()}"); } pageContent = webClient.DownloadString(url); webClient.Dispose(); } catch (Exception) { pageContent = string.Empty; } return(pageContent); }