Javascript XMLHttpRequest Post method
Posted
by
user535617
on Stack Overflow
See other posts from Stack Overflow
or by user535617
Published on 2010-12-21T16:48:27Z
Indexed on
2011/01/07
21:54 UTC
Read the original article
Hit count: 210
Hey So I have a question about posting using an XMLHttpRequest. In theory, if I am to post a username and password to an https domain (which I have yet to get working, unfortunately) would the responseText then change to the next website, or should the text fields become filled in? What normally happens is you navigate to this page via browser, enter a username and password, and it uses a POST method when the submit button is clicked, doing some authentication under the hood and returning a different page. I feel like maybe the responseText should even stay exactly the same (which is what happens now), but I don't know as I have no experience with this kind of thing.
this.requests[1].open("POST", "https://" + this.address, true);
var query = "target=%2Fcgi-bin%2FStatusConfig.cgi%3FPage%3Dindex&userfile=&username=user&password=pass&log+in=Log+in";
this.requests[1].setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
this.requests[1].setRequestHeader("Content-length", query.length);
this.requests[1].setRequestHeader("Keep-Alive", 115);
this.requests[1].setRequestHeader("Connection", "keep-alive");
this.requests[1].setRequestHeader("Host", this.address);
this.requests[1].send(query);
this.requests[1].onreadystatechange = onReadyStateChange1;
Then basically onReadyStateChange1 displays the responseText when ready.
Any light that could be shed on what SHOULD be happening with the post and responseText would be very appreciated. As would any advice in getting the new, logged into page.
For further clarification, what I'm trying to do is log in and then return the new page, because the login page displays only log in information/functionality and the page after logging in has a lot of relevant information. I'm not trying to check the credentials as much as I'm trying to get it (the script) to log in so it can access the next page. Granted, the credentials will have to be valid for that.
Thanks all.
© Stack Overflow or respective owner