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