1

I'm in the process of making a personal program for myself (I've made a thread on it before) in which I make an Amazon recent items checker where I can just pull all my purchases and populate them in a listview on the form.

up to this point I've been using a webbrowser, but that method is taking way to long. So I figured I would have a go with webrequests and try it that way, I've been trying and trying but I can't replicate the POST request to login to http://Amazon.com.

Here's my code:

var request = (HttpWebRequest)WebRequest.Create("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%2Fgp%2Fyourstore%2Fhome%3Fie%3DUTF8%26ref_%3Dgno_signin");

    var postData = "All this data is so long, there's no point of posting it";
    var data = Encoding.ASCII.GetBytes(postData);

    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = data.Length;

    using (var stream = request.GetRequestStream())
    {
        stream.Write(data, 0, data.Length);
    }

    var response = (HttpWebResponse)request.GetResponse();

    var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
    File.WriteAllText(@"C:\Users\Admin\Desktop\Source.html", responseString);

As you can see I'm outputting the source to check if it logs in, but it always just gives me the login page right back, does anyone have any ideas?

Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
Frank
  • 185
  • 13
  • `` For a start you will need to make a get request to retreive this token, plus save any cookies and send them with the post request. There is probably a number of other security measures as well - websites dont like you doing this, so they make it hard – Steve Jul 03 '14 at 12:26
  • Ye, I know that for sure; alright so I'll start by trying to grab that token. Thank you – Frank Jul 03 '14 at 12:29
  • possible duplicate of [PHP Curl - Cookies problem](http://stackoverflow.com/questions/7522149/php-curl-cookies-problem) the highest voted answer used to work in 2011 but not anymore. See also http://stackoverflow.com/questions/6888549/programatically-login-to-amazon-with-c-sharp - where it's pointed out what the javascript on amzon's sign-in pages do. – Wolfgang Fahl Nov 26 '14 at 18:14

0 Answers0