Javascript 卡纳';t在chrome上保存cookies
我想在从服务器获取的客户端上保存cookie。 在Firefox上一切正常,但chrome仍然显示“此设置Cookie被阻止,因为其域属性对于当前主机url无效” 我已经读了很多教程,但我仍然无法理解 它在本地主机上运行良好,但当我尝试在heroku上运行它时,我在chrome上收到此警告,无法保存cookie 我在Heroku上创建了测试项目,客户端位于“https://cookietestclient.herokuapp.com,而服务器位于https://cookieservertest.herokuapp.com/" 这是我的JS获取代码:Javascript 卡纳';t在chrome上保存cookies,javascript,spring-boot,cookies,Javascript,Spring Boot,Cookies,我想在从服务器获取的客户端上保存cookie。 在Firefox上一切正常,但chrome仍然显示“此设置Cookie被阻止,因为其域属性对于当前主机url无效” 我已经读了很多教程,但我仍然无法理解 它在本地主机上运行良好,但当我尝试在heroku上运行它时,我在chrome上收到此警告,无法保存cookie 我在Heroku上创建了测试项目,客户端位于“https://cookietestclient.herokuapp.com,而服务器位于https://cookieservertest.
function addCookie (){
fetch("https://cookieservertest.herokuapp.com/api/v1/test",{
method:"POST",
credentials:"include",
mode:"cors"
})
.then(res=>res.json())
.then(data=>{
console.log(data)
})
}
和Spring启动代码:
@RestController
@RequestMapping(path = "api/v1/test")
public class BasicReturnCookie {
@PostMapping
@CrossOrigin(origins = "https://cookietestclient.herokuapp.com", allowCredentials = "true",
allowedHeaders = "https://cookietestclient.herokuapp.com", maxAge = 3600)
public void getMapping(HttpServletResponse response){
ResponseCookie cookie = ResponseCookie.from("userName", "Jarek")
.domain("/")
.sameSite("None")
.build();
response.addHeader(HttpHeaders.SET_COOKIE, cookie.toString());
}
}
SameSite=None的Cookie现在还必须指定安全属性(它们需要安全上下文/HTTPS)
ResponseCookie cookie=ResponseCookie.from(“用户名”、“Jarek”)
.domain(“/”)
.sameSite(“无”)//它不工作。即使我添加了安全和httponly,“如果我添加了安全”是什么意思?您是否将安全设置为true?
ResponseCookie cookie = ResponseCookie.from("userName", "Jarek")
.domain("/")
.sameSite("None") // <- delete this
.build();