【发布时间】:2020-05-27 21:08:57
【问题描述】:
当我尝试使用我的 Angular 客户端调用我的后端时遇到问题 我在 post、put 和 delete 方法中总是有这个错误:
Access to XMLHttpRequest at 'http://localhost:8087/categories' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
这是我的后台
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Headers", "Origin, Accept, X-Requested-With, Content-Type,Access-Control-Request-Method, Access-Control-Request-Headers, credential, X-XSRF-TOKEN, authorization");
response.setHeader("Access-Control-Expose-Headers", "Access-Control-Allow-Origin, Access-Control-Allow-Credentials, authorization");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT, PATCH");
response.setHeader("Access-Control-Allow-Credentials", "true");
if (request.getMethod().equals("OPTIONS")) {
response.setStatus(HttpServletResponse.SC_OK);
}
我现在不明白为什么我的客户被屏蔽了
【问题讨论】:
标签: angular spring spring-boot spring-security jwt-auth