0
这里IM usingapplication/JSON但即时得到方法不被允许Angular2 HTTP POST无法加载资源:服务器与405状态响应(不允许的方法)
Service.js
AddEmp(Emp: Employee): Observable<Employee[]> {
let headers = new Headers({ 'Content-Type': 'application/json' });
let body = JSON.stringify(Emp);
let options = new RequestOptions({ headers: headers });
return this._http.post(this.Url2, +body, options).map(this.extractData).catch(this.handleError);
}
private extractData(res: Response) {
let body = res.json();
return body || {};
}
这里即时消费我的服务 Component.ts
submit(data: Employee){
this._HttpService.AddEmp(data)
.subscribe(data => this.Employees = data, error => console.log(data),() => console.log());
}
的WebAPI
[Route("SaveEmp")]
[HttpPost]
public string SaveData(Employee emp)
{
return "OK";
}