首页 > 解决方案 > httpclient 响应中不存在 Set-Cookie

问题描述

我正在尝试以角度创建登录页面并保存由我们的 Spring Boot 应用程序创建的 cookie

这就是我们在 BE 中创建 cookie 的方式

val cookie = createCookie(jwtProperties.cookieName, token, expirySeconds,
                false, true, jwtProperties.cookieDomain, "/",
                "sample comment")
response.addCookie(cookie)
response.status = HttpServletResponse.SC_OK
response.contentType = MediaType.APPLICATION_JSON_VALUE
response.writer.write(objectMapper.writeValueAsString(JwtGetDto(token)))

这是角度请求

const headers = new HttpHeaders({
            'Content-Type': 'application/json'
        });
const url = `${environment.api_url}/api/v1/auth/login`
return this._http.post(url, JSON.stringify({ username: username, password: password }), { observe: 'response', headers: headers});

这是浏览器中的响应

浏览器响应

这是邮递员的回应

邮递员回应

我试图添加withCredentials:true角度请求,但仍然没有用

标签: javascriptangularspring-bootpostmanangular-httpclient

解决方案


推荐阅读