protected WebClient WebClient() { WebClient client = new WebClient(); client.AddCookie(_cookieCollection); return(client); }
public static ReturnInformation.Return Search(string query, char?character = null, QueryArgs.Status?status = null, QueryArgs.Mode?mode = null, int?page = null) { WebClient webclient = new WebClient(); string s = webclient.DownloadString(Path(query, character, status, mode, page)); ReturnInformation.Return r = JsonConvert.DeserializeObject <ReturnInformation.Return>(s); return(r); }
public static BitmapImage GetCAPTCHA(Uri uri, out CAPTCHAData data) { string image; string sync; string hash; Regex r_image = new Regex("<img src=" + @"\" + '"' + "data:image/jpeg;base64,(?<image>[^.]*)" + @"\" + '"' + " " + "class=" + @"\" + '"' + "d-block mw-100" + @"\" + '"' + ">"); //<img src=\"(?<image>[^.]*)\" class=\"d-block mw-100\"> Regex r_sync = new Regex("<input name=" + @"\" + '"' + "sync" + @"\" + '"' + " " + "type=" + @"\" + '"' + "hidden" + @"\" + '"' + " " + "value=" + @"\" + '"' + @"(?<sync>\d+)" + @"\" + '"' + ">"); //<input name=\"sync\" type=\"hidden\" value=\"(?<sync>\d+)\"> Regex r_hash = new Regex("<input name=" + @"\" + '"' + "hash" + @"\" + '"' + " " + "type=" + @"\" + '"' + "hidden" + @"\" + '"' + " " + "value=" + @"\" + '"' + "(?<hash>[^" + '"' + "]*)" + @"\" + '"' + ">"); //<input name=\"sync\" type=\"hidden\" value=\"(?<hash>[^"]*)\"> string CAPTCHAPage = null; try { CAPTCHAPage = new WebClient().DownloadString(uri); } catch (WebException e) { StreamReader sR = new StreamReader(e.Response.GetResponseStream()); CAPTCHAPage = sR.ReadToEnd(); } Match m_image = r_image.Match(CAPTCHAPage); Match m_sync = r_sync.Match(CAPTCHAPage); Match m_hash = r_hash.Match(CAPTCHAPage); image = m_image.Groups["image"].Value; sync = m_sync.Groups["sync"].Value; hash = m_hash.Groups["hash"].Value; if (image == string.Empty | sync == string.Empty || hash == string.Empty) { throw new Exception("Failed Get CAPTCHAdata"); } else { data = new CAPTCHAData(); data.sync = sync; data.hash = hash; data.uri = uri; } BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = new MemoryStream(Convert.FromBase64String(image)); bitmapImage.EndInit(); return(bitmapImage); }
public static CookieCollection PostCAPTCHA(string response, CAPTCHAData data) { WebClient client = new WebClient(); string formData = "response=" + response + "&" + "sync=" + data.sync + "&" + "hash=" + data.hash; client.Referer = data.uri.ToString(); client.Host = data.uri.Host; client.ContentType = "application/x-www-form-urlencoded"; client.UploadString(data.uri, formData); string Header = client.ResponseHeaders.Get("Set-Cookie"); client.Dispose(); return(WebClient.GetAllCookiesFromHeader(Header, data.uri.Host.ToString())); }
internal override byte[] Download() { if (_cookieCollection == null) { throw new Exception("Bloodcat No Cookie Existed."); } byte[] file; WebClient client = new WebClient(); client.AddCookie(_cookieCollection); _beatmapsetPackage.OnProgressChanged(new ProgressChangedEventArgs(0, "Downloading")); file = client.DownloadData(Path(_beatmapsetPackage)); _beatmapsetPackage.OnProgressChanged(new ProgressChangedEventArgs(90, "Download Complete")); return(file); }
public static bool IsCookieValid(CookieCollection cookieCollection) { WebClient client = new WebClient(); client.AddCookie(cookieCollection); string s = client.DownloadString(Path(Methods.user)); ReturnInformation.User user = JsonConvert.DeserializeObject <ReturnInformation.User>(s); if (user.logged_in) { return(true); } else { return(false); } }
public static bool IsCookieValid(CookieCollection cookieCollection) { WebClient client = new WebClient(); client.AddCookie(cookieCollection); client.Method = "Head"; //Bloodcat 对 Cookie 进行加密 与 User-Agent 配合验证 try { client.DownloadData("http://bloodcat.com/osu/s/4079"); return(true); } catch (WebException e) { Console.WriteLine(e.Message); return(false); } }