用户管理项目关于两次请求sessionid不一致的解决

网上找了很多方法都试过,今天早上起来在项目里面搜索withCredentials的配置,找到

屏幕截图 2024-11-09 130400.png 发现在request里设置credentials=='include'就行 app.tsx: image.png 另外我们还要在后端配置跨域的config类 `package com.zjy.config;

import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration public class CorsConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { //添加映射路径 registry.addMapping("/**") //是否发送Cookie .allowCredentials(true) .allowedOriginPatterns("") //放行哪些请求方式 .allowedMethods(new String[]{"GET", "POST", "PUT", "DELETE"}) //放行哪些原始请求头部信息 .allowedHeaders("") .maxAge(3600) //暴露哪些原始请求头部信息 .exposedHeaders("*"); } } `然后就解决了登录不上的问题~

0个评论
点击登录,快来和大家讨论吧~
表情
图片
暂无评论
鱼友1066
下载 APP