Api angular 2服务不发送数据-不可处理实体

Api angular 2服务不发送数据-不可处理实体,api,angular,service,Api,Angular,Service,我正在尝试使用表单发送数据(电子邮件、密码) 但它总是给我这个回复 Unprocessable Entity {"email":["The email field is required."],"password":["The password field is required."]} 服务 login(email:string,password:string){ console.log(email,password); return this._http.post('ht

我正在尝试使用表单发送数据(电子邮件、密码) 但它总是给我这个回复

Unprocessable Entity
{"email":["The email field is required."],"password":["The password field is required."]}
服务

 login(email:string,password:string){
    console.log(email,password);
    return this._http.post('http://localhost:8000/api/signin',JSON.stringify({email:email,password:password}))
    .map(res =>{
        // login successful if there's a jwt token in the response
         let user = res.json();
         if(user && user.token){
               localStorage.setItem('currentUser',JSON.stringify(user));
           }
    });
}
Login.Component.ts

 login(){
  console.log(this.model.email,this.model.password);
  this.authenticationservice.login(this.model.email,this.model.password)
    .subscribe(
        data => {
          this.router.navigate([this.returnUrl]);
        });
形式


登录
电子邮件
密码
登录
{{error}}

邮递员的回应 试试这个:

let headers = new Headers();
headers.append('Content-Type', 'application/json');
let options = {
    headers: headers
};
let body = JSON.stringify({email:email,password:password});
return this.http.post(url, body, options).map(...);
试试这个:

let headers = new Headers();
headers.append('Content-Type', 'application/json');
let options = {
    headers: headers
};
let body = JSON.stringify({email:email,password:password});
return this.http.post(url, body, options).map(...);

内容类型
应用程序/json
标题添加到您的请求中:

login(email:string,password:string) {
        let bodyString = JSON.stringify({ email: email, password: password });
        let headers = new Headers({ 'Content-Type': 'application/json' });

        return this._http.post('http://localhost:8000/api/signin', bodyString, {headers: headers})
            .map(res =>{
            // login successful if there's a jwt token in the response
                let user = res.json();
                if(user && user.token){
                    localStorage.setItem('currentUser',JSON.stringify(user));
                }
            });
}

内容类型
应用程序/json
标题添加到您的请求中:

login(email:string,password:string) {
        let bodyString = JSON.stringify({ email: email, password: password });
        let headers = new Headers({ 'Content-Type': 'application/json' });

        return this._http.post('http://localhost:8000/api/signin', bodyString, {headers: headers})
            .map(res =>{
            // login successful if there's a jwt token in the response
                let user = res.json();
                if(user && user.token){
                    localStorage.setItem('currentUser',JSON.stringify(user));
                }
            });
}

表格是必需的