locked
how to access Amazon account using webrequest RRS feed

  • Question

  • User-651745648 posted

    Hi,

    I am a beginner in web development. I have wrote a code to login and redirect me to the landing page, but it doesn't work. Could anyone please tell me what I did wrong? Please see my codes below. 

            string LOGIN_URL = "https://www.amazon.com/gp/sign-in.html";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(LOGIN_URL);
            string postdata = "email=xxxx&password=yyyyy";
            CookieContainer cookies = new CookieContainer();
            request = (HttpWebRequest)WebRequest.Create(LOGIN_URL);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.CookieContainer = cookies;
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            request.GetResponse().Close();
            request = (HttpWebRequest)WebRequest.Create("https://sellercentral.amazon.com/gp/homepage.html");
            request.Accept = "*/*";
            request.AllowAutoRedirect = true;
            request.CookieContainer = cookies;
            response = (HttpWebResponse)request.GetResponse();
            StreamReader responseReader = new StreamReader(response.GetResponseStream());
            string responseData = responseReader.ReadToEnd();
            response.Close();
            responseReader.Close();
            Response.Write(responseData);

    Any experts please advise,




    Tuesday, September 8, 2009 3:19 PM

Answers

  • User2130758966 posted

    Hey,

    Im sorry, I didnt have time this morning to do a proper reply so I left it open. Its been open all day and now I am going to bed and I still dont have time!

    The quick version of what I want to say is that you are using the wrong technique.

    The HttpWebRequest is not for the end user. Its for you if you wanted to pull the html from another site into your code and mess with the data, or if you wanted to test the headers or something like that.

    If you want to send the user to the location then you have to use Response.Redirect("http://www.example.com"); and you also use it for in-site redirects like Response.Redirect("~/anotherpage.aspx");

    Amazingly there isnt a built in way in .net for you to do http POST requests such as submitting a form to another site (like a payment gateway for example). In that case the solution I use is something like this:

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 9, 2009 7:37 PM
  • User-1363023537 posted

    Hi,
     It seems you are trying to programatically login. better look at thier API to access their web.

    or refer http://www.codeproject.com/KB/aspnet/asproxy.aspx

    Satalaj

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 10, 2009 6:56 AM
  • User2130758966 posted

    Yeah thats a good point, you should look here for code examples to use the amazon web services:

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 10, 2009 7:18 AM
  • User-1363023537 posted

    Hi Pipo,
     I don;t think they amazon will allow you to do screen scrapping. They might have implemnted cpatcha challange, 
    or Java script anti-bot / anti robot kinda stuff on their site.
     see if you are able to login to their site using http://hidemyass.com . if you succeeded then the code which was publish on code project will help you to fix your code.
     Better try what they have exposed to you via their API, as per rtpHarry link in previos post.

    - Satalaj

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 10, 2009 10:15 AM

All replies

  • User2130758966 posted

    Hey,

    Im sorry, I didnt have time this morning to do a proper reply so I left it open. Its been open all day and now I am going to bed and I still dont have time!

    The quick version of what I want to say is that you are using the wrong technique.

    The HttpWebRequest is not for the end user. Its for you if you wanted to pull the html from another site into your code and mess with the data, or if you wanted to test the headers or something like that.

    If you want to send the user to the location then you have to use Response.Redirect("http://www.example.com"); and you also use it for in-site redirects like Response.Redirect("~/anotherpage.aspx");

    Amazingly there isnt a built in way in .net for you to do http POST requests such as submitting a form to another site (like a payment gateway for example). In that case the solution I use is something like this:

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 9, 2009 7:37 PM
  • User-1363023537 posted

    Hi,
     It seems you are trying to programatically login. better look at thier API to access their web.

    or refer http://www.codeproject.com/KB/aspnet/asproxy.aspx

    Satalaj

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 10, 2009 6:56 AM
  • User2130758966 posted

    Yeah thats a good point, you should look here for code examples to use the amazon web services:

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 10, 2009 7:18 AM
  • User-651745648 posted

    Thank you you guys for answering. I will do more research from your articles. However, could you please help me understand why my code is not working? This code works on some websites. I just do not understand what have been missing from my code. 

    Thank you for helping.

    Thursday, September 10, 2009 9:38 AM
  • User-1363023537 posted

    Hi Pipo,
     I don;t think they amazon will allow you to do screen scrapping. They might have implemnted cpatcha challange, 
    or Java script anti-bot / anti robot kinda stuff on their site.
     see if you are able to login to their site using http://hidemyass.com . if you succeeded then the code which was publish on code project will help you to fix your code.
     Better try what they have exposed to you via their API, as per rtpHarry link in previos post.

    - Satalaj

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 10, 2009 10:15 AM
  • User-651745648 posted

    Thank you so much Satalaj and rtpHarry, I will follow your suggestion and let you know how it goes.


    Thank you so much for all your help.

    Thursday, September 10, 2009 11:21 AM
  • User-806595978 posted

    Hi, pupo.asp.net

    Have you solved this problem,?

    I am also getting the same problem , please help me if you have already solved th issue,

    Thanks

    Wednesday, September 7, 2011 3:38 AM