I am trying to simulate the angular2 Http user login. let them describe the situation as a roar.
I have a php application that users can log into the throw http://sample.com/login.phpurl system (the form exists with a username and password, the user must fill in the input and click the submit button), and if the login is successful, they are redirected to http://sample.com/dashboard.php.
therefore, I create a message Httpwith form data that has a "username" and "password". and set the Http header content-typeas application/x-www-form-urlencoded.
the problem is that I need to access the response header of the first request ( http://sample.com/login.php ) , but Http will respond to the second response header of the request (http://sample.com/dashboard.php ).
is that any way to prevent an http redirect? or throw an error with status 302?
var headers = new Headers({'Content-Type':'application/x-www-form-urlencoded'});
var options = new RequestOptions({ headers: headers });
Http.post("http://sample.com/login.php",'username=admin&password=123' , options)
.subscribe(success => {
}, error => {
}
);
source
share