后端的配置代码中增加 .csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) 要将http-only设置为false才可以获取 这样就成功了