Trying to make a GET request from Angular to Spring Java, but encountering error code 415
zone.js:3243 GET http://localhost:8080/user/friend/1 415
Below is my Spring Java code for the endpoint:
@RequestMapping(
value = "/friend/{idUser}",
method = RequestMethod.GET,
consumes = "application/json",
produces = "application/json")
public ResponseEntity<List<Friendship>> getFriend(@PathVariable Long idUser) {
return new ResponseEntity<List<Friendship>>(userServiceImpl.getFriends(idUser), HttpStatus.OK);
}
Here is the Angular code used to request data from the backend:
getFriends(idUser) {
console.log('UNA', idUser);
const config = new HttpHeaders().set('Content-Type', 'application/json');
const url = 'http://localhost:8080/user/friend/' + idUser;
const body = JSON.stringify({"idOwner": idUser});
return this.http.get<Object[]>(url);
}