本地项目都能正常运行。请求头中携带了cookie
部署到线上,请求头中没有cookie.响应头有个set-cookie不知道什么意思。。(这里我测试把domain配置去掉,还是不行)
我在后端也加了domain的配置
server:
address: 0.0.0.0
port: 8101
servlet:
context-path: /api
# cookie 30 天过期
session:
cookie:
max-age: 2592000
domain: x.x.x.x (服务器外网ip)
后端登录成功后会记录用户的登录态
// 3. 记录用户的登录态
request.getSession().setAttribute(UserConstant.USER_LOGIN_STATE, user);
前端react框架+umi 在请求拦截器中配置了
withCredentials: true,
我刚刚登录以后,随便掉个接口,居然给我返回了未登录。。。
问题应该在于cookie无法种上的原因。。但是为什么本地没问题,但到了线上就不行了呢。。求大佬解惑。。
猜测是跨域了,试试服务器端加上
Access-Control-Allow-Credentials: true
头。