Javascript 从webapp设置cookie。刚刚赢了';行不通
几个小时来我一直在这个问题上大发雷霆。我就是不能把饼干做好。我正在设置的cookie似乎从未正确保存或发送回 情况是,cookie:Javascript 从webapp设置cookie。刚刚赢了';行不通,javascript,ajax,google-app-engine,web-applications,cookies,Javascript,Ajax,Google App Engine,Web Applications,Cookies,几个小时来我一直在这个问题上大发雷霆。我就是不能把饼干做好。我正在设置的cookie似乎从未正确保存或发送回 情况是,cookie: w_self.response.set_status(200) # Put the token in the cookies. "str()" is used because without it, there is a unicode error w_self.response.headers.add_header(str('Set-Cookie'),
w_self.response.set_status(200)
# Put the token in the cookies. "str()" is used because without it, there is a unicode error
w_self.response.headers.add_header(str('Set-Cookie'), str('token=%s; max_age=360;' % token))
# The user
r_object['user'] = the_user
# Respond
w_self.response.out.write(json.dumps(r_object))
- 发送完全相同的请求时是否会被发回
- 使用其他路径发送请求时,不会返回李>
- 重新启动浏览器时似乎不会持续
- 不会出现在Chrome开发者工具“资源”区域中
w_self.response.set_status(200)
# Put the token in the cookies. "str()" is used because without it, there is a unicode error
w_self.response.headers.add_header(str('Set-Cookie'), str('token=%s; max_age=360;' % token))
# The user
r_object['user'] = the_user
# Respond
w_self.response.out.write(json.dumps(r_object))
如果再次请求此页面,则会将cookie发送回服务器:
但似乎没有保存在任何地方,因为在开发人员工具中探索cookie时,我永远找不到它:
当请求路径不完全相同的资源时,也不会发送此消息(“注销”而不是“登录”):
$.ajax({
type: 'POST',
url: '/rest/logout/',
data: JSON.stringify({something:'else'}),
error: function(jqXHR, status, errorThrown){...},
success: function(data, status, jqXHR){...}
});
这就是请求的样子:
:
如果未设置路径,则默认情况下只将其发送回设置路径的路径,如您所见
我还认为它也应该是Max Age,而不是像现在这样的Max_Age,但是不管webapp2给你的响应对象是什么,你都有一个想法-我相信这会很好地解决问题。我不确定为什么设置标题不起作用,也许你可以尝试使用set cookie方法:
# Saves a cookie in the client.
response.set_cookie('some_key', 'value', max_age=360, path='/',
domain='example.org', secure=True)
以下是set\u cookie
方法的源代码: