【问题标题】:React cookie integration with spring将 cookie 与 spring 集成
【发布时间】:2020-08-31 06:28:01
【问题描述】:

我有一个网站,后端是 spring,前端是 React。我使用

在后端保存了一个cookie
Cookie cookie = new Cookie("userId", testDTO.getId());
userCookie.setPath("/");
response.addCookie(userCookie);

但是当 react 在控制器上发布请求时,我的浏览器没有得到那个 cookie。 Firefox 中的存储空间是空的。

前端代码:

const requestOptions = {
            method: 'POST',
            headers: {'Content-Type': 'application/json'},
            body: JSON.stringify({
                name: username,
                stayLogged: false
            })
        };

       fetch('http://localhost:8080/health-check/post',requestOptions)
           .then(response => response.json())
           .then(data =>{console.log(data);})

【问题讨论】:

标签: java reactjs spring-boot cookies


【解决方案1】:

我修好了。刚刚添加到控制器中的后期映射 @CrossOrigin(origins = "http://localhost:3000", allowCredentials = "true")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-15
    • 2011-02-18
    • 2012-08-24
    • 1970-01-01
    • 1970-01-01
    • 2012-10-20
    • 1970-01-01
    • 2016-03-11
    相关资源
    最近更新 更多