inSessionOtpCode==null
改了@CrossOrigin(allowCredentials = "true",allowedHeaders = "*")和xhrFields:{withCredentials:true},
这两个地方还是null,springboot版本是2.0改了@CrossOrigin(allowCredentials = "true",allowedHeaders = "*")和xhrFields:{withCredentials:true},
这两个地方还是null,springboot版本是2.02021-08-10
他妈的搞了好几天终于解决这个问题了,帖子里在response里设置header里set-cookie的不会生效试过了,响应头里会有两个set-cookie不知道为什么,可能是chorme版本问题。视频spring里使用的是2.0.5.RELEASE版本
这个版本找不到sameSite属性,我将springboot升级到然后设置一个config类,在config类中设置如下的配置
@Bean
public CookieSerializer httpSessionIdResolver(){
DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
// 源码默认为Lax
// private String sameSite = "Lax";
cookieSerializer.setSameSite("None");
cookieSerializer.setUseSecureCookie(true);
return cookieSerializer;
}
亲测有用,被这个bug折磨死了!!!!!在类中加入
@Autowired private HttpServletResponse httpServletResponse;
之后,在接口中设置samesite=None, httponly,secure等属性
ResponseCookie cookie = ResponseCookie.from("JSESSIONID", httpServletRequest.getSession().getId() ) // key & value
.httpOnly(true) // 禁止js读取
.secure(true) // 在http下也传输
.domain("localhost")// 域名
.path("/") // path
.maxAge(3600) // 1个小时候过期
.sameSite("None") // 大多数情况也是不发送第三方 Cookie,但是导航到目标网址的 Get 请求除外
.build()
;
httpServletResponse.setHeader(HttpHeaders.SET_COOKIE, cookie.toString());举报