首页 > 解决方案 > 跨域读取阻塞 (CORB) 阻止了 MIME 类型 application/json 的跨域响应

问题描述

从 reactjs 调用服务到 spring boot。低于错误 Cross-Origin Read Blocking (CORB) blocks cross-origin response with MIME type application/json

反应代码:

fetch(URL, {method: 'GET',
            contentType: 'application/json',
            mode: 'no-cors'
          }).then (function (response) { return response.json()})
            .then(function (json) {debugger;console.log(json)})
            .catch(function (error) {debugger;console.log(error)});

spring code:

    @GetMapping(path="/user/{aid}", produces= {"application/json"})
    public Optional<User> getUser(@PathVariable int aid) {
        return userRepo.findById(aid);
    }

错误信息:

跨域读取阻塞 (CORB) 阻止了 MIME 类型 application/json 的跨域响应

标签: ajaxreactjsspring-bootmicroservices

解决方案


您需要从您的 spring 代码应用程序中允许 CORS。希望这可以帮助。为 RESTful Web 服务启用跨源请求


推荐阅读