我无法设置 cookiedomain
使用跨站点请求添加归档。我试图通过 jquery ajax 调用 request 来实现这一点。
是否可以在除 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=/
Code:
$.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
},
});
在火狐中一切都很好。 Chrome 没有设置 cookie。仅当域字段被删除时,所有内容才适用于每个浏览器。我可以看到在下一个请求中(设置 cookie 后)该 cookie 出现在标头中。响应设置 cookie 后的 Firefox 请求示例(当响应具有域字段时):
Cookie: Auth=l_hash=123456&user=xyz&remember_me=false