【问题标题】:request as been blocked by CORS:Response to preflight request doesn't pass access control check: It does not have HTTP ok status请求被 CORS 阻止:对预检请求的响应未通过访问控制检查:它没有 HTTP ok 状态
【发布时间】:2019-08-09 02:57:56
【问题描述】:

我正在做这个请求:

 saveNewPermissions=(newGroupPermissions,curentGroupId)=>{
    window.alert(this.baseUrl+"/addPermission/group/"+curentGroupId)
    return fetch(this.baseUrl+"/addPermission/group/"+curentGroupId, {
        method: 'PUT',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            permissions: newGroupPermissions
        })
    })
}

但是执行该方法时出现以下错误: CORS 策略已阻止从源“http://localhost:3000”获取“http://localhost:8083/uaa/addPermission/group/2”的访问权限:对预检请求的响应未通过访问控制检查:它没有 HTTP ok 状态。 我已经有 CORS Chrome 插件,我可以执行其他类型的请求,例如帖子和获取,并且接收请求的方法具有 @CrossOrigin(allowCredentials = "true")。该方法在 java 中使用 springboot。

【问题讨论】:

  • 你的服务器api必须启用CORS,它与你的客户端或浏览器无关

标签: reactjs react-native cors


【解决方案1】:

我使用带有默认参数的 @CrossOrigin 只是 get 和 post,这就是为什么 put 不起作用,你需要 put:

@CrossOrigin(allowCredentials = "true",methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT})

【讨论】:

    猜你喜欢
    • 2020-07-30
    • 2020-01-29
    • 2020-06-06
    • 1970-01-01
    • 2021-09-16
    • 2020-01-14
    • 2020-02-11
    • 2021-04-15
    • 2019-07-07
    相关资源
    最近更新 更多