I facing issue with CORS in spring boot. I have configured CORS like this
@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**");
}
}
which I suppose enables all header and other stuff.
It works excellently with GET request
$.get("someUrl, function(data, status){
console.log(data[0].latitude);
});
But whenever I make POST request like this
$.ajax({
url: 'someUrl',
type: 'post',
dataType: 'json',
crossDomain: true,
contentType: "application/json; charset=utf-8",
success: function (data) {
console.log(data);
},
data: object
});
I get the following
OPTIONS XHR "someUrl" [HTTP/1.1 403 Forbidden 4ms]
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at "someUrl".
(Reason: CORS header 'Access-Control-Allow-Origin' missing).
How can I solve this issue?
POST
from other domains. What version of Boot are you using and from what user agent do youPOST
your requests? May other dependencies in your project override your Cors settings (or maybe more explicit configuration on the controllers?)?