I make an application with a spring server and angular for the client. I'm trying to make a post request and have this error:
Failed to load http://localhost:8080/statuts:
"No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 415."
I have followed the Spring tutoriel : https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-cors-controller and nothing works for me.
As for my spring code I have put the cross origin annotation that works for all other request like get and put (if I delete this line the others request send exactly the same error)
@CrossOrigin(origins = "http://localhost:4200")
public class ExempleController {
@PostMapping(path="", consumes = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody Exemple addExemple(HttpServletRequest request) throws IOException {
Exemple exemple = new Exemple();
Exemple updatedStatut = objectMapper.readerForUpdating(exemple).readValue(request.getReader());
statutRepository.save(updatedExemple);
return exemple;
}
I also tried it with the global config but same issue
My request in angular :
create(exemple: Exemple){
return this.http.post("localhost:8080/exemples", JSON.stringify(exemple));
}
Thanks you for your help
== Edit ==
I haven't mention it but my request is working as it works just fine with PostMan it is a communication problem between the client and the server