我一直在尝试使用以下代码从本地数据库中删除一项。不幸的是无法删除项目,但出现420错误。请问问题专家的建议是什么?
data.services.ts
deleteDiscipline(id: number, requestBody:any) {
return this.http.post(this.configService.apiUrl + 'disciplines/' + id + '/delete', requestBody, httpOptions )
.pipe(
catchError(this.handleError('deleteitem', requestBody))
);
}
component.ts
deleteData($event:any){
if($event == "delete") {
this.requestBody = {
name : { "en" : this.selectedItem.name.en, "de" : this.selectedItem.name.de},
id : this.selectedId
}
this.dataService.deleteDiscipline(this.selectedId, this.requestBody )
.subscribe( data => {
this.logger.log("deleted successfully" + data);
this.notificationService.showNotification('success', '', 'Deleted successfully');
this.router.navigate(['technicalSettings/disciplines']);
})
}
}
服务器脚本
@POST
@Path(ID_PATH + DELETE)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response delete(@PathParam(ID) final String id) throws Exception {
----- code goes here --
}
答案 0 :(得分:0)
如果您的API需要删除请求,则应使用http.delete
而不是http.post
。
最好共享用于删除的API方法。
编辑: 正如您在评论中提到的,它是POST API一样,该错误在API端,因为是从Angular端发送请求,并且它正在从API中获取错误。调试API以捕获确切的错误。