When I try to set Content-Type:application/json
I get a CORS error Reason: CORS header 'Access-Control-Allow-Origin' missing
Here is my Cors Override in Spring MVC:
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowCredentials(true).allowedMethods("GET", "POST", "PUT", "DELETE","OPTIONS").allowedHeaders("*").allowedOrigins("http://localhost:4200");
}
My Post API:
@RequestMapping(value = "/seanPost", method = RequestMethod.POST)
public String post(HttpServletRequest request, @RequestBody TrackFileStatusFindForm form ) {
My Request in Angular:
options = {
headers: new HttpHeaders()
.set('Accept', 'application/json')
.set('Content-Type', 'application/json')
};
this.http.post(this.APP_URL + '/seanPost', JSON.stringify(this.model), this.options)
.subscribe(
data => {
this.postId = data;
console.log(this.postId);
},
error => {
console.log('Error occured', error);
}
)
My Spring project is deployed on WebLogic 12c locally and I am using https if that helps.
Thanks
试试这个:
private httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) };
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.