Last post Sep 07, 2011 03:38 AM by ishtiaq_ahmed
Sep 08, 2009 03:19 PM|pupo.asp.net|LINK
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 = (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();
Any experts please advise,
Sep 09, 2009 07:37 PM|rtpHarry|LINK
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:
Sep 10, 2009 06:56 AM|satalaj|LINK
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
Sep 10, 2009 07:18 AM|rtpHarry|LINK
Yeah thats a good point, you should look here for code examples to use the amazon web services:
Sep 10, 2009 09:38 AM|pupo.asp.net|LINK
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.
Sep 10, 2009 10:15 AM|satalaj|LINK
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.
Sep 10, 2009 11:21 AM|pupo.asp.net|LINK
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.
Sep 07, 2011 03:38 AM|ishtiaq_ahmed|LINK
Have you solved this problem,?
I am also getting the same problem , please help me if you have already solved th issue,