我正在尝试使用休息服务来登录页面。但我收到此错误状态代码400错误的请求 这是我的登录服务
@Injectable()
export class LoginService{
constructor(private _http:Http){}
postJSON(){
var json = JSON.stringify({var1: 'username', var2: 'password'});
var params = 'json =' +json;
var headers = new Headers();
headers.append('Content-type', 'application/json');
return this._http.post('http://localhost:8080/login', params,{
headers: headers
}).map(res => res.json());
}
}[This is my rest service][1]
这是我的LoginComponent.ts
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss'],
providers:[LoginService]
})
export class LoginComponent {
postData: string;
constructor(private _httpService: LoginService) {}
OnTestLogin()
{
this._httpService.postJSON().subscribe(
data => this.postData = JSON.stringify(data),
error => alert(error),
() => console.log("Finished")
);
}
}
我对Angular和Rest服务很新,为什么它会给状态代码400错误请求?