Front
const axios = Axios.create({
baseURL: "http://localhost:8066", cookie
// baseURL: "http://192.168.1.107:8066", cookie
withCredentials:true,
timeout: 5000,
});
when baseURL is set to native IP, you cannot carry cookie, but the backend can get cookie
. backend code
configure
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
//
registry.addMapping("/**")
//
.allowedOrigins("*")
//.allowedOrigins("http://localhost:8080")
//
.allowCredentials(true)
//
.allowedMethods("*")
//
.maxAge(3600);
}
}
all tried, there is no difference
.allowedOrigins("*").allowedOrigins("http://localhost:8080")
write cookie:
public static void writeCookie(HttpServletResponse response, String cookieName, String value) {
Cookie cookie = new Cookie(cookieName, value);
cookie.setPath("/");
cookie.setMaxAge(3000 * 60);
response.addCookie(cookie);
}