带有域字段的CORS cookie仅在使用jQuery AJAX的Firefox中设置

使用跨站点请求添加domain时,我无法设置cookie。 我试图通过jquery ajax调用请求来实现这一点。

是否有可能让它在除firefox以外的其他浏览器中运行?

一些请求标题:

 Accept:application/json, text/javascript, */*; q=0.01 Content-Length:55 Content-Type:application/x-www-form-urlencoded; charset=UTF-8 Host:localhost:53862 Origin:http://localhost:54265 Referer:http://localhost:54265/ 

响应标题:

 Access-Control-Allow-Credentials:true Access-Control-Allow-Headers:x-requested-with, origin, content-type, accept, Proxy-Connection Access-Control-Allow-Methods:GET,POST,PUT,OPTIONS, DELETE Access-Control-Allow-Origin:http://localhost:54265 Set-Cookie:Auth=l_hash=123456&user=xyzl&remember_me=false; expires=Fri, 18 Jan 2013 13:42:10 GMT; domain=localhost; path=/ 

码:

 $.ajax({ type: "PUT", url: apiHost + "api/account/login/", data: $("#loginBarForm").serialize(), dataType: "json", contentType: "application/x-www-form-urlencoded; charset=UTF-8", crossDomain: true, xhrFields: { withCredentials: true }, }); 

在Firefox中一切都很好。 Chrome未设置Cookie。 仅当域字段被删除时,所有浏览器都在运行。 我可以在下一个请求(设置cookie后)中看到cookie出现在标题中。 响应设置cookie后的firefox请求示例(当响应有域字段时):

 Cookie: Auth=l_hash=123456&user=xyz&remember_me=false 

我认为问题可能在于localhost ,它不是Set-Cookie标头的有效域。 根据RFC ,它必须包含至少一个“嵌入”点。 FireFox可以以较少限制的方式实现此目的。 请尝试使用您的IP地址。

我遇到了同样的问题,结果发现浏览器设置阻止了第三方Cookie(Chrome>设置>高级设置>隐私>内容设置>阻止第三方Cookie和网站数据)。 允许cookie解决了问题!