我似乎无法获得"补丁"在Angular2中工作的http方法。我所有的其他请求(put,post,delete,get)都运行良好,但是" patch"给了我一个" 405:方法不允许"错误。我尝试了以下代码无济于事:
export class DataService
{
public headers: Headers;
public options: RequestOptions;
constructor(private http:Http)
{
this.headers = new Headers({ 'Content-Type': 'application/json;charset=utf-8', 'Accept': 'q=0.8;application/json;q=0.9' });
this.options = new RequestOptions({ headers: this.headers });
}
patchRecord(url:string, record: any): Promise<any>
{
let body = JSON.stringify(record);
return this.http.patch(url, body, this.options)
.toPromise()
.then()
.catch(this.handleError);
}
private handleError(error: any)
{
console.log('An error occurred', error);
return Promise.reject(error.essage || error)
}
}
我正在使用Visual Studio Code和NG Live Development Server。