I want to send an HTTP POST request by submitting a form to my server, which is located at a different domain (enabled cors in the server script using node.js).
Thi
For those users who are finding an answer to make CORS requests from Angular JS. Firstly, don't spend enough time in adding unnecessary headers in your JS configuration. You don't have to change anything in your frontend. Just add the following annotation in your controller or at the method level.
@CrossOrigin
If you want to enable CORS for any specific URL then use the following annotation,
@CrossOrigin(origins = "http://localhost:9000")
The above solution is given for the Controller method CORS configuration. You shall also do Global CORS configuration by adding the following in your application class.
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedOrigins("http://localhost:9000");
}
};
}
Reference : https://spring.io/guides/gs/rest-service-cors/
I hope this help. Peace! :)