//do ponownego merga public static void test01() { WebClient wc = new WebClient(); wc.Headers.Add("Content-Type: application/x-www-form-urlencoded"); wc.Headers.Add("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5"); wc.Headers.Add("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); wc.Headers.Add("Accept-Encoding: identity"); wc.Headers.Add("Accept-Language: en-US,en;q=0.8"); wc.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3"); // http://napisy24.pl/search.php?str=piotr+dudzik+%B1%EA%E6+%F3%BF%BC%BFd%F3%F3%F3pa // piotr dudzik ąęć óżźżdóóópa // Console.WriteLine("EscapeDataReplace: " + Uri.EscapeDataString(testString).Replace("%20", "+")); string title = "Hobbit"; string encodedTitle = Uri.EscapeDataString(title).Replace("%20", "+"); string napisyURL = "http://napisy24.pl/search.php?str="; string requestURL = string.Format("{0}{1}", napisyURL, encodedTitle); //string response = wc.DownloadString(requestURL); // http://napisy24.pl/logowanie/ // form_logowanieMail=waaaggh&form_logowanieHaslo=d00pad00pa&form_loginZapamietaj=1&postAction=sendLogowanie string loginData = @"form_logowanieMail=waaaggh&form_logowanieHaslo=d00pad00pa&form_loginZapamietaj=1&postAction=sendLogowanie"; string cookie = string.Empty; //cookie = wc.ResponseHeaders["Set-Cookie"].ToString(); //wc.UploadString("http://napisy24.pl/logowanie/", "POST", loginData); //wc.Headers.Add("Cookie", cookie); //string r1= wc.UploadString("http://napisy24.pl/logowanie/", "POST", loginData); //string DocumentText = wc.DownloadString("http://napisy24.pl/download/67682/"); // The.Hobbit.2012.DVDScr.XVID.AC3.HQ.Hive-CM8.avi // Znaleziono 0 filmów dla "wpisz nazwę filmu basfasfdfądź napisów jakich szukasz " // Nie znaleziono wyników // Znaleziono 2 filmów dla "hobbit " // The Hobbit: An Unexpected Journey // Hobbit: Niezwykła podróż, Hobbit: Nieoczekiwana podróż // DVDRip.XviD-RISES // 06-04-2013 // http://napisy24.pl/download/67682/ CookieAwareWebClient wcc = new CookieAwareWebClient(); wcc.Headers.Add("Content-Type: application/x-www-form-urlencoded"); wcc.Headers.Add("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5"); wcc.Headers.Add("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); wcc.Headers.Add("Accept-Encoding: identity"); wcc.Headers.Add("Accept-Language: en-US,en;q=0.8"); wcc.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3"); //string swcc1 = wcc.DownloadString("http://napisy24.pl/logowanie/"); string swcc2 = wcc.UploadString("http://napisy24.pl/logowanie/", "POST", loginData); cookie = wcc.ResponseHeaders["Set-Cookie"].ToString(); wcc.Headers.Add("Cookie", cookie); wcc.DownloadFile("http://napisy24.pl/download/67682/", @"C:\aaa.zip"); string swcc3 = wcc.DownloadString("http://napisy24.pl/download/67682/"); }
public override bool Login() { CookieContainer cookieJar = new CookieContainer(); _client = new CookieAwareWebClient(cookieJar); _client.Referer = HOME_URL; // the website sets some cookie that is needed for login string response = _client.DownloadString(HOME_URL); Cookie tokenCookie = cookieJar.List().FirstOrDefault(c => c.Name == "csrftoken"); StringBuilder postData = new StringBuilder(); postData.Append("email=" + HttpUtility.UrlEncode(Username) + "&"); postData.Append("password="******"&"); postData.Append("remember=False="); // the csrf token is sent in the hader _client.Headers.Add("User-Agent", USER_AGENT); _client.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01"); _client.Headers.Add("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); _client.Headers.Add("Referer", HOME_URL); _client.Headers.Add("X-Requested-With", "XMLHttpRequest"); _client.Headers.Add("X-CSRFToken", tokenCookie.Value); response = _client.UploadString(LOGIN_API, postData.ToString()); JObject jObject = JObject.Parse(response); JToken jToken = jObject.GetValue("success"); if (!jToken.Value<bool>()) { //The query returned false, either not authenticated or forbiddent (403) Console.WriteLine("Wrong email or password logging into Edx."); return false; } //Now get the goods (cookies should be set!) return true; }
private void UploadThread(object param) { var parms = (object[]) param; var error = (ErrorReturn) parms[3]; error.Code = ErrorCodes.Succeeded; error.Exception = null; error.ReportedError = null; try { CookieAwareWebClient client = new CookieAwareWebClient(); var text = client.DownloadString("http://minecraft.net/login"); Match match = Regex.Match(text, @"<input type=""hidden"" name=""authenticityToken"" value=""(.*?)"">"); string authToken = null; if (match.Success) authToken = match.Groups[1].Value; if (authToken == null) return; var data = new NameValueCollection(); data.Add("authenticityToken", authToken); data.Add("username", (string)parms[0]); data.Add("password", (string)parms[1]); data.Add("redirect", "/profile"); var returnData = Encoding.UTF8.GetString(client.UploadValues("https://minecraft.net/login", data)); match = Regex.Match(returnData, @"<p class=""error"">([\w\W]*?)</p>"); if (match.Success) { error.ReportedError = match.Groups[1].Value.Trim(); error.Code = ErrorCodes.WrongCredentials; } else { var dict = new Dictionary<string, string>(); dict.Add("authenticityToken", authToken); if ((error.Exception = client.UploadFileEx("http://minecraft.net/profile/skin", parms[2].ToString(), "skin", "image/png", dict)) != null) error.Code = ErrorCodes.Unknown; } } catch (Exception ex) { error.Exception = ex; } finally { Invoke(delegate { _pleaseWaitForm.Close(); }); } }
public OAuth2TokenResponse GetAccessTokenFromUserKey(string userKey,string state,params string[] scopes) { var request = CreateAuthorizeRequest(userKey, state, scopes); CookieAwareWebClient client = new CookieAwareWebClient(this); var result = client.DownloadString(request); var callback = new Uri(client.LastPage); string stateInResponse = string.Empty; var code = HandleAuthorizeCallback(callback, out stateInResponse); System.Diagnostics.Debug.Assert(stateInResponse == state); return base.GetToken(code); }
public void RaiseCallbackEvent(string arg) { Result = null; try { string cmd, par = string.Empty; int i = arg.IndexOf(':'); if (i == -1) cmd = arg; else { cmd = arg.Substring(0, i); par = arg.Substring(i + 1); } switch (cmd) { case "load": Html.DocumentNode html; var preview = PreviewElement; // if Preview element exists load preview else HtmlElement.Children. if (preview != null) html = preview.Children; else html = Element.Children; EditorConverter.Export(html); Services.JavaScriptTextEditor.Converter.Export(html, out Result); break; case "save": var oldText = Element.Children.Text; // save old text preview = CreatePreviewElement(); Services.JavaScriptTextEditor.Converter.Import(preview.Children, par); EditorConverter.Import(preview.Children); // TODO preview.Children.AddIdentation(preview.ChildIdentation); CheckParseErrors(); Element.Preview(); // page is now saved, now get the new html via a WebClient request to the saved page. try { var web = new CookieAwareWebClient(); // start a webrequest to the new preview page. web.UseDefaultCredentials = true; web.Encoding = Encoding.UTF8; web.Headers[HttpRequestHeader.UserAgent] = Request.UserAgent; //web.Headers[HttpRequestHeader.TransferEncoding] = "UTF8"; //web.Headers[HttpRequestHeader.ContentEncoding] = "UTF8"; foreach (var key in Request.Cookies.Keys.OfType<string>()) { var cookie = Request.Cookies[key]; var wc = new Cookie(cookie.Name, cookie.Value, cookie.Path, Request.Url.Host); wc.Expires = cookie.Expires; web.Cookies.Add(wc); } Html.Element e = null; var dochtml = web.DownloadString(Request.Url.AbsoluteUri); // get the new preview page's html. if (dochtml != null) { // parse the received html page for the Container control. if (string.IsNullOrEmpty(Container.ClientID)) CreateChildControls(); // this is needed so we know the Container.ClientID, because otherwise Container get's not instantiated in CallbackEvent. var doc = new Html.Document(dochtml); e = doc.Find(Container.ClientID); // get our element out of the html. } if (e != null) { Result = e.Children.Text; // return the element's html } else { Element.Children.Text = oldText; Save(); throw new Exception("Invalid HTML."); } } catch (Exception ex) { // exception viewing the new preview page Element.Children.Text = oldText; // reset text Save(); Result = null; throw ex; } break; default: throw new NotSupportedException("EditableContent: Unknown callback command."); } } catch (Exception ex) { Services.Log.Error("EditableContent callback exception:", ex); throw ex; } }
private CookieAwareWebClient setupCAS(Credentials cred){ var client = new CookieAwareWebClient(); var data = new NameValueCollection(); data["access"] = "authcate"; data["username"] = cred.name; data["password"] = cred.password; data["request_uri"] = "/authentication/cas/login?service=" + WEB_METL_URL; data["submit"] = "login"; var casResponse = client.UploadValues(CAS_URL,data); var wm3Response = client.DownloadString(WEB_METL_URL); var cookies = client.GetCookies(new Uri(WEB_METL_URL)); foreach(var _cookie in cookies) { var cookie = (Cookie)_cookie; var cookieString = String.Format("{0}={1}; domain={2}", cookie.Name, cookie.Value, cookie.Domain); WebCore.SetCookie(WEB_METL_URL, cookieString); isHealthy = true; } return client; }
private bool Login(String username, String password) { client = new CookieAwareWebClient(); client.BaseAddress = @"http://www.pixiv.net/"; NameValueCollection loginData = new NameValueCollection(); loginData.Add("mode", "login"); loginData.Add("pixiv_id", username); loginData.Add("pass", password); loginData.Add("skip", "1"); client.UploadValues("https://www.secure.pixiv.net/login.php", "POST", loginData); string htmlSource = client.DownloadString("mypage.php"); Console.WriteLine(client.DownloadString("mypage.php").Contains("pixiv.user.loggedIn = true")); return client.DownloadString("mypage.php").Contains("pixiv.user.loggedIn = true"); }
//web requests private string getRequest(string url, NameValueCollection get = null, string referral = "") { //initialize client CookieAwareWebClient webClient = new CookieAwareWebClient(cookies); //generate GET uri string request = url; if (get != null) { request += "?"; int it = 0; foreach (string s in get) { foreach (string v in get.GetValues(s)) { if (it != 0) request += "&"; request += s + "=" + v; it++; } } } //Set webclient referrer if (referral != "") webClient.Headers["Referer"] = referral; //issue the request and return output string output = webClient.DownloadString(request); webClient.Dispose(); return output; }