1
I’m making a request through the Angularjs at port 3000:
function _registrarNovaAposta(aposta) {return $http.post("http://localhost:8080/sga-api/apostas/nova-aposta", aposta);}
to the endpoint:
@POST
@Path("/nova-aposta")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public String registrarNovaAposta(Aposta aposta) {
apostaService.registrar(aposta);
return "ok";
}
but I get the following error on the console: "Access to Xmlhttprequest at 'http://localhost:8080/sga-api/bets/new bet' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested Resource."
the problem is that GET returns the data normally, but with the POST of this CORS problem, I tried to configure the "headers" in $http.post but it didn’t work.
I am using the Tomcat 9 server in the back-end