【发布时间】:2019-01-11 10:51:52
【问题描述】:
我无法获取 cookie
春天
Spring boot 正在发送多个 cookie,通过使用下面
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class SampleController {
@PostMapping("/test")
public Object test(HttpSession session, HttpServletResponse response) {
String cookie1 = "first";
String cookie2 = "second";
Cookie firstCookie = new Cookie("uid", cookie1);
firstCookie.setPath("/");
firstCookie.setMaxAge(60 * 60 * 24 * 30);
Cookie secondCookie = new Cookie("token", cookie2);
secondCookie.setPath("/");
secondCookie.setMaxAge(60 * 60 * 24 * 30);
response.addCookie(firstCookie);
response.addCookie(secondCookie);
}
}
反应原生
使用两个 cookie 发送响应, 并在下面反应本机代码示例以捕获 cookie
function test() {
fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
credentials: 'include',
'Content-Type': 'application/json',
}
}).then((response) => {
for (const [name, value] of response.headers) {
if (name === "set-cookie") {
console.log(value)
}
}
});
}
我使用 response.header 检查了 cookie,但我最后添加了一个(第二个 - cookie2)
我也试过 python,邮递员,我可以看到三个 cookie 包括 jsession Postman Cookie View
如何获得两个 cookie?
【问题讨论】:
标签: spring-boot react-native cookies