I am creating angular application to get data from laravel API,
let headers = new Headers();
headers.append('Content-Type', 'application/X-www-form-urlencoded');
const loginInfo = 'email=' + email + '&password=' + password;
return this.http.post(this.ApiUrl + '/api/v1/login', loginInfo, {headers: headers}).do((resp) => {
if (resp) {
console.log(resp);
localStorage.setItem(this.tokenKey, JSON.stringify(resp.json().access_token));
console.log(localStorage);
}
}).catch((error) => {
return Observable.of(false);
});
this is the auth service I call from component to subscribe this method, but i keep getting "400 bad request". I also have tried to use
loginInfo = new URLSearchParams();
loginInfo.append('email', email);
loginInfo.append('password', password);
or using form-data content type. but all return me same error.
let urlSearchParams = new URLSearchParams();
urlSearchParams.append('password', password);
urlSearchParams.append('email', email);
let loginInfo = urlSearchParams.toString();
.toString() the parameters
Try this
const loginInfo = 'email=' + email + '&password=' + password;
let body = JSON.stringify(loginInfo);
return this.http.post(this.ApiUrl + '/api/v1/login', body,{headers:headers}).do((resp) => {
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.