【发布时间】:2022-01-26 02:37:15
【问题描述】:
我的前端应用程序给出了这个错误:
从源“http://localhost:3000”访问“http://localhost:9025/customer/registerDocs/”处的 XMLHttpRequest 已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查: 它没有 HTTP ok 状态。
何时调用:
updateDocsStatus() {
return ApiService.postData('http://localhost:9025/customer/registerDocs');
}
这是 API 中的控制器方法:
@PostMapping(value = Constants.REGISTER_DOCS_PATH,
consumes = {MediaType.APPLICATION_JSON_VALUE},
produces = {MediaType.APPLICATION_JSON_VALUE})
@ResponseStatus(HttpStatus.OK)
public void registerUserForDocs(HttpServletRequest request){
String username = securityService.getUsername(request);
customerHelper.registerCustomerForEdocs(username);
}
我不禁觉得问题出在前端。我在这里遗漏了什么明显的东西吗?
【问题讨论】:
-
你知道 CORS 是如何工作的,特别是客户端和服务器的职责是什么?如果没有,你应该先了解这些。
标签: javascript java rest cors