简体   繁体   English

Spring MVC & Angular - 原因:缺少 CORS 标头“Access-Control-Allow-Origin”

[英]Spring MVC & Angular - Reason: CORS header ‘Access-Control-Allow-Origin’ missing

When I try to set Content-Type:application/json I get a CORS error Reason: CORS header 'Access-Control-Allow-Origin' missing当我尝试设置Content-Type:application/json出现 CORS 错误原因:CORS header 'Access-Control-Allow-Origin' missing

Here is my Cors Override in Spring MVC:这是我在 Spring MVC 中的 Cors 覆盖:

@Override
public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**").allowCredentials(true).allowedMethods("GET", "POST", "PUT", "DELETE","OPTIONS").allowedHeaders("*").allowedOrigins("http://localhost:4200");
}

My Post API:我的帖子API:

@RequestMapping(value = "/seanPost", method = RequestMethod.POST)
public  String post(HttpServletRequest request, @RequestBody TrackFileStatusFindForm form ) {

My Request in Angular:我在 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.我的 Spring 项目在本地部署在 WebLogic 12c 上,如果有帮助,我正在使用 https。

Thanks谢谢

试试这个:

private httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) };

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 原因:缺少 CORS header 'Access-Control-Allow-Origin' - Reason: CORS header ‘Access-Control-Allow-Origin’ missing 原因:即使在Java资源中明确指定,CORS标头“ Access-Control-Allow-Origin”也丢失 - Reason: CORS header ‘Access-Control-Allow-Origin’ missing even though explictly specificed in java resource (原因:缺少 CORS header 'Access-Control-Allow-Origin')。 还显示 id undefined - (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). also showing id undefined CORS:不存在“ Access-Control-Allow-Origin”标头Angular 2 - CORS : No 'Access-Control-Allow-Origin' header is present Angular 2 Angular 2打字稿-启用CORS标头'Access-Control-Allow-Origin' - Angular 2 Typescript - Enable CORS header ‘Access-Control-Allow-Origin’ Socket.io + Nodejs + Angular2 +-缺少CORS标头'Access-Control-Allow-Origin' - Socket.io + Nodejs + Angular2+ - CORS header 'Access-Control-Allow-Origin' missing Nginx中的Angular2-缺少CORS标头'Access-Control-Allow-Origin' - Angular2 in nginx - CORS header 'Access-Control-Allow-Origin' missing 不允许多个 CORS 标头“Access-Control-Allow-Origin”/缺少 CORS 标头“Access-Control-Allow-Origin”) - Multiple CORS header ‘Access-Control-Allow-Origin’ not allowed / CORS header ‘Access-Control-Allow-Origin’ missing) 添加了 cors 映射的 Angular/Spring - 被 CORS 策略阻止:请求的资源上不存在“Access-Control-Allow-Origin”标头 - Angular/Spring with cors mapping added - blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource Angular 6中没有'Access-Control-Allow-Origin'标头 - No 'Access-Control-Allow-Origin' header in Angular 6
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM