Я пытаюсь отправить запрос PUT из angular5 в API Spring, но я получаю сообщение об ошибке.
Это angularvention.service.ts:
updateIntervention(id:number){
if(this.authService.getToken()==null) {
this.authService.loadToken();
}
return this.http.put(this.host+"/updateIntervention/"+id,
{headers:new
HttpHeaders({'Authorization':this.authService.getToken()})});
}
Intervention.component.ts
valider(ref: Intervention){
this.intervService.updateIntervention(ref.id)
.subscribe((data:any)=>{
console.log('there is no error ! ');
},err=>{
console.log('there is an error ! ');
})
ref.valid = !ref.valid;
}
В Spring-Boot:
@RequestMapping(value="/updateIntervention/{id}",method = RequestMethod.PUT)
public Intervention update(@PathVariable Long id){
System.out.println("in intevention update");
Intervention I = new Intervention();
I = interventionRepo.getOne(id);
I.setValid(true); // it's boolean , this is the goal from this update
interventionRepo.save(I);
return I
}
Как ошибка, я получаю в угловых:
{"timestamp":1527443447949,"status":401,"error":"Unauthorized"}
Как ошибка В Spring-Boot:
access.AccessDeniedException: Access is denied
PS: этоработает, когда я отправляю в angular и id, и объект Ref. Весной я пишу
public Intervention update(@PathVariable Long id , @RequestBody Intervention I){ ... }
Но мне это не нужно, так как все, что я хочу, это изменить атрибут, действительный в объекте Intervention.
Я использую httpClient.
Есть идеи?