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(); }); } }
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; }
//Returns a cookie aware webclient authenticated with the speciefied email and password public static CookieAwareWebClient GetAuthenticatedWebClient(string solderUrl, string email, string password) { string loginAddress = solderUrl + "login"; System.Collections.Specialized.NameValueCollection loginData = new System.Collections.Specialized.NameValueCollection {{"email", email}, {"password", password}}; CookieAwareWebClient client = new CookieAwareWebClient(); client.UploadValues(loginAddress, loginData); 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"); }
private string postRequest(string url, NameValueCollection post = null, string referral = "") { //initialize client CookieAwareWebClient webClient = new CookieAwareWebClient(cookies); //Set webclient referrer if (referral != "") webClient.Headers["Referer"] = referral; //issue the request byte[] responseBytes = webClient.UploadValues(url, "POST", post); string result = Encoding.UTF8.GetString(responseBytes); //clear buffers and return result webClient.Dispose(); return result; }