App Engine似乎总是将多个具有相同名称的标题合并为一个。例如,如果在CGI中设置它
print "Set-Cookie: foo=bar"
print "Set-Cookie: spam=egg"
实际传送给浏览器的是
Set-Cookie: foo=bar, spam=egg
这当然是错的。正确的解决方案是
Set-Cookie: foo=bar; spam=egg
或者根本不合并它们。我怎样才能做到这一点?谢谢!
答案 0 :(得分:1)
我相信GAE正在做正确的事情。多个cookie以逗号分隔,而不是分号。分号用于分隔单个cookie的参数。我没有时间查找RFC链接,但您可以通过互联网查看示例:
<强> CODE 强>
import httplib
c = httplib.HTTPConnection("www.facebook.com")
myHeaders = {
'Content-Type': 'text/html',
'User-agent':
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12",
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Keep-Alive': '300',
'Connection': 'keep-alive',
'Accept-Language': 'en-us,en;q=0.5',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
}
c.request("GET", "/login.php", body="", headers=myHeaders)
r = c.getresponse()
print r.getheaders()
<强>结果
[...其他标题剪断......
('set-cookie','datr = 5j9DTSaOPEd5Rxc9X23IB7KB; expires = Sun,27-Jan-2013 22:15:02 GMT; path = /; domain = .facebook.com; httponly,lsd = 0l0sd; path = /; domain = .facebook.com,reg_fb_gate = http%3A%2F%2Fwww.facebook.com%2Flogin.php; path = /; domain = .facebook.com,reg_fb_ref = http%3A%2F%2Fwww.facebook。 com%2Flogin.php; path = /; domain = .facebook.com')
希望这有帮助 伊恩