ajax - 跨域读取阻塞 (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 的跨域响应
解决方案
您需要从您的 spring 代码应用程序中允许 CORS。希望这可以帮助。为 RESTful Web 服务启用跨源请求
推荐阅读
- apache-spark - 从 spark 插入覆盖正在更改配置单元表目录的权限和所有者
- java - 使用底栏自定义 android 布局?
- python - Pytest:Windows 致命异常:访问冲突
- java - 没有分隔符的输入字符串的标记化
- r - 如何将连续日期转换为离散类别?
- vue.js - 在 Vuejs 和 PHP 中一次推送和插入
- python - 如何解决错误:AttributeError: module 'pyglfw' has no attribute 'pyglfwInit'
- sql - 更新时(一行与多行连接) - 执行计划问题
- python - 读取在远程 Windows 命令提示符下连续运行的缓冲区数据
- reactjs - Ant Design 如何处理 Form.List 从底层数据结构访问值?