【发布时间】:2021-01-16 01:14:14
【问题描述】:
我这几天一直在尝试从我用 Go 编写的网络服务器设置一个 cookie,一切看起来都正常,但它就是行不通。
我的 Set-Cookie 标头:
Set-Cookie: session_token=token; Path=/; Expires=Date; Max-Age=120000; HttpOnly; SameSite=Strict
我已尝试编辑所有值并删除和添加其他字段,但没有任何帮助。如果我将请求设置为获取并直接导航到带有浏览器 cookie 的链接,并且在 Postman 中它就在那里,但是当我尝试使用 fetch 获取 http 请求时它不起作用。
我知道credentials: "same-origin" 和credentials: "include" 但它们不起作用。
这是我的 js 获取代码:
const log_in = (e) => {
// data entry validation and stuff
const url = "/signin";
fetch(ip + url, {
credentials: "same-origin",
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
username: document.getElementById("username").value,
password: document.getElementById("password").value,
}),
}).then(
() => console.log("recieved")
);
};
【问题讨论】:
标签: javascript http cookies fetch setcookie