我有带有 API 的服务器(Node.js + Express + CORS)(作为通过 JWT 的“登录”)和通过服务器的 API 登录的 React 客户端应用程序。需要通过axios发送cookies
\nwithCredentials = true ,\nRun Code Online (Sandbox Code Playgroud)\n但是如果服务器 + React 在 192.168.0.1 上运行并且客户端(Web 浏览器)从 192.168.0.!1 看到 - 这是下一个错误:
\n\'Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at `http://localhost:5002/api/login. (Reason: CORS header \xe2\x80\x98Access-Control-Allow-Origin\xe2\x80\x99 does not match \xe2\x80\x98http://localhost:3000\xe2\x80\x99).`\nRun Code Online (Sandbox Code Playgroud)\n注意: axios 不能withCredentials = true与服务器的 cors 很好地配合使用origin: \'*\',但在这种情况下客户端没有“auto coockies”。
我的问题:使用 auto coockies 创建 React axios 的正确方法是什么\n(通过
\nwithCredentials = true\nRun Code Online (Sandbox Code Playgroud)\n …