Ajax 跨源读取阻塞(CORB)使用MIME类型application/json阻塞跨源响应
从reactjs调用服务到spring boot。低于误差 跨源读取阻塞(CORB)使用MIME类型application/json阻塞跨源响应 反应代码:Ajax 跨源读取阻塞(CORB)使用MIME类型application/json阻塞跨源响应,ajax,reactjs,spring-boot,microservices,Ajax,Reactjs,Spring Boot,Microservices,从reactjs调用服务到spring boot。低于误差 跨源读取阻塞(CORB)使用MIME类型application/json阻塞跨源响应 反应代码: fetch(URL, {method: 'GET', contentType: 'application/json', mode: 'no-cors' }).then (function (response) { return response.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);
}
fetch(URL,{method:'GET',
contentType:'应用程序/json',
模式:“无cors”
}).then(函数(响应){return response.json()})
.then(函数(json){debugger;console.log(json)})
.catch(函数(错误){debugger;console.log(错误)});
弹簧代码:
@GetMapping(path=“/user/{aid}”,products={“application/json”})
公共可选getUser(@PathVariable int-aid){
返回userRepo.findById(aid);
}
错误消息:
跨源读取阻塞(CORB)使用MIME类型application/json阻塞跨源响应
您需要从spring代码应用程序中允许CORS。希望这能有所帮助。应用程序需要标头,而您正在传递不同的标头, 例如:spring需要应用程序/json头和传递的文本/html 反应代码:
fetch(url, {
method: 'POST',
headers: {'Content-Type':'application/json'},
body: JSON.stringify(data)})
正如在那个url中提到的,我在下面添加了一行,但并没有运气@交叉原点(原点=)