Example #1
0
        private async Task PostRedeemCode(string code, string user, string pass)
        {
            using (var request = new WebRequestExtend())
            {
                Debug.WriteLine("processing redeem code {0}", code, "");

                Dispatcher.Invoke(() => LogTextBlock.Text = "Login...");

                // download login form
                Debug.WriteLine("downloading login form");
                var loginFormString = await Task.Run(() =>
                {
                    return request.DownloadString("https://www.amazon.com/ap/signin?_encoding=UTF8&openid.assoc_handle=usflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.com%2F%3Fref_%3Dnav_signin");
                });

                // login
                //var loginFormString = await Task.Run(() =>
                //{
                //    return _request.DownloadString("https://www.amazon.com/ap/signin?_encoding=UTF8&openid.assoc_handle=usflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.com%2F%3Fref_%3Dnav_signin");
                //});

                if (string.IsNullOrEmpty(loginFormString))
                {
                    Debug.WriteLine("login form not found");
                    return;
                }

                Debug.WriteLine("login form download completed: {0}", loginFormString.Substring(0, loginFormString.Length / 100) + "...");

                // create form to post data
                Debug.WriteLine("create login form with user={0}, pass={1}", user, pass);
                var loginForm = Tools.GetInputs(loginFormString, "signIn") ?? new Dictionary<string, string>();
                if (loginForm.Count == 0)
                {
                    loginForm.Add("email", string.Empty);
                    loginForm.Add("password", string.Empty);
                }

                loginForm["email"] = user;
                loginForm["password"] = pass;

                var postLogin = Tools.GetUrlEncoded(loginForm);
                Debug.WriteLine("posting login form: {0}", postLogin, "");

                var accessTokenForm = await Task.Run(() =>
                {
                    try
                    {
                        request.UploadString("https://www.amazon.com/ap/signin", postLogin);
                        Debug.WriteLine("login success");
                        return request.DownloadString("https://www.amazon.com/gc/redeem"); // download cookies
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("login error: {0}", ex.Message, "");
                        return string.Empty;
                    }
                });

                Debug.WriteLine("posting redeem code {0}", code, "");
                Dispatcher.Invoke(() => LogTextBlock.Text = string.Format("Login success. Processing redeem code {0}", code));

                // get acess token
                // var accessTokenForm = await Task.Run(() => _request.DownloadString("https://www.amazon.com/gc/redeem"));

                // get cross-sharing-resource-token
                var pattern = @"<input type='hidden' name='csrf' value='(.*)' />";
                var csrf = string.Empty;
                var m = Regex.Match(accessTokenForm, pattern);
                if (m.Success)
                {
                    csrf = m.Groups[1].Value;
                }

                // create redeem form
                var redeem = new Dictionary<string, string>();
                redeem["csrf"] = csrf;
                redeem["claimCode"] = code;
                var redeemData = Tools.GetUrlEncoded(redeem);
                Debug.WriteLine("redeem params: {0}", redeemData, "");

                var result = await Task.Run(() => request.UploadString("https://www.amazon.com/gc/redeem/result", redeemData)) ?? string.Empty;
                var success = result.Contains("$1.00 has been added to your Gift Card Balance");

                Debug.WriteLine("redeem result: {0}", result.Substring(0, result.Length / 100) + "...", "");

                if (success)
                {
                    _totalSuccess++;
                }

                Debug.WriteLine("{0}/{1} redeem successful", _totalSuccess, _totalCode);
                Dispatcher.Invoke(() => LogTextBlock.Text = string.Format("{0}/{1} redeem successful", _totalSuccess, _totalCode));
            }
        }
Example #2
0
        private async Task PostRedeemCode(string code, string user, string pass)
        {
            using (var request = new WebRequestExtend())
            {
                Debug.WriteLine("processing redeem code {0}", code, "");

                Dispatcher.Invoke(() => LogTextBlock.Text = "Login...");

                // download login form
                Debug.WriteLine("downloading login form");
                var loginFormString = await Task.Run(() =>
                {
                    return(request.DownloadString("https://www.amazon.com/ap/signin?_encoding=UTF8&openid.assoc_handle=usflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.com%2F%3Fref_%3Dnav_signin"));
                });

                // login
                //var loginFormString = await Task.Run(() =>
                //{
                //    return _request.DownloadString("https://www.amazon.com/ap/signin?_encoding=UTF8&openid.assoc_handle=usflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.com%2F%3Fref_%3Dnav_signin");
                //});

                if (string.IsNullOrEmpty(loginFormString))
                {
                    Debug.WriteLine("login form not found");
                    return;
                }

                Debug.WriteLine("login form download completed: {0}", loginFormString.Substring(0, loginFormString.Length / 100) + "...");

                // create form to post data
                Debug.WriteLine("create login form with user={0}, pass={1}", user, pass);
                var loginForm = Tools.GetInputs(loginFormString, "signIn") ?? new Dictionary <string, string>();
                if (loginForm.Count == 0)
                {
                    loginForm.Add("email", string.Empty);
                    loginForm.Add("password", string.Empty);
                }

                loginForm["email"]    = user;
                loginForm["password"] = pass;

                var postLogin = Tools.GetUrlEncoded(loginForm);
                Debug.WriteLine("posting login form: {0}", postLogin, "");

                var accessTokenForm = await Task.Run(() =>
                {
                    try
                    {
                        request.UploadString("https://www.amazon.com/ap/signin", postLogin);
                        Debug.WriteLine("login success");
                        return(request.DownloadString("https://www.amazon.com/gc/redeem")); // download cookies
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("login error: {0}", ex.Message, "");
                        return(string.Empty);
                    }
                });

                Debug.WriteLine("posting redeem code {0}", code, "");
                Dispatcher.Invoke(() => LogTextBlock.Text = string.Format("Login success. Processing redeem code {0}", code));

                // get acess token
                // var accessTokenForm = await Task.Run(() => _request.DownloadString("https://www.amazon.com/gc/redeem"));

                // get cross-sharing-resource-token
                var pattern = @"<input type='hidden' name='csrf' value='(.*)' />";
                var csrf    = string.Empty;
                var m       = Regex.Match(accessTokenForm, pattern);
                if (m.Success)
                {
                    csrf = m.Groups[1].Value;
                }

                // create redeem form
                var redeem = new Dictionary <string, string>();
                redeem["csrf"]      = csrf;
                redeem["claimCode"] = code;
                var redeemData = Tools.GetUrlEncoded(redeem);
                Debug.WriteLine("redeem params: {0}", redeemData, "");

                var result = await Task.Run(() => request.UploadString("https://www.amazon.com/gc/redeem/result", redeemData)) ?? string.Empty;

                var success = result.Contains("$1.00 has been added to your Gift Card Balance");

                Debug.WriteLine("redeem result: {0}", result.Substring(0, result.Length / 100) + "...", "");

                if (success)
                {
                    _totalSuccess++;
                }

                Debug.WriteLine("{0}/{1} redeem successful", _totalSuccess, _totalCode);
                Dispatcher.Invoke(() => LogTextBlock.Text = string.Format("{0}/{1} redeem successful", _totalSuccess, _totalCode));
            }
        }