【发布时间】:2021-12-09 07:13:29
【问题描述】:
我有带有 API 的服务器(Node.js + Express + CORS)(作为通过 JWT 的“登录”)和通过服务器的 API 登录的 React 客户端应用程序。需要通过axios发送coockies
withCredentials = true ,
但如果服务器 + react 在 192.168.0.1 和客户端(Web 浏览器)上运行,从 192.168.0.!1 看到 - 这是下一个错误:
'Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at `http://localhost:5002/api/login. (Reason: CORS header ‘Access-Control-Allow-Origin’ does not match ‘http://localhost:3000’).`
注意:没有 withCredentials = true 的 axios 可以很好地与带有 origin: '*' 的服务器的 cors 配合使用,但在这种情况下没有来自客户端的“auto coockies”。
我的问题:使用自动 cookie 创建 React axios 的正确方法是什么 (通过
withCredentials = true
) 对于 Internet 中的任何客户端?
【问题讨论】:
-
请编辑您的问题以改进格式。这将帮助其他人为您找到解决方案。 stackoverflow.com/help/formatting