我的挑战是把饼干和有效载荷一起发送。我只是向一个现有的、正在运行的程序添加一个cookie。这首歌很快就到了。而且,我在浏览器控制台没有收到任何错误。你知道吗
我似乎能够发送一个cooke,以及我的JSON数据。你知道吗
当我在Chrome的开发者工具中查看标题时,我看到了cookie。但是,当我在Application>;>;cookie选项卡中查找cookie时,什么都没有。所以,一个cookie头似乎是由客户端发送的,而不是存储它。你知道吗
在客户处。。。。文档.cookie为空。你知道吗
我的测试代码正在创建一个名为sessionID的cookie。你知道吗
这是Chrome中的响应头:您可以看到我的假sessionID cookie:
Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin:null
Content-Type:text/plain
Date:Wed, 23 Nov 2016 22:41:10 GMT
Server:BaseHTTP/0.6 Python/3.5.2
Set-Cookie:sessionID=4jjdd7ghhq
这是显示没有饼干的截图。 no cookies in application
以下是我用Python3编写的服务器代码:
def do_OPTIONS(self):
self.send_response(200)
self.send_header("Access-Control-Allow-Origin", self.headers["Origin"])
self.send_header("Access-Control-Allow-Credentials", "true")
self.send_header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
self.send_header('Access-Control-Allow-Headers', 'Content-Type')
self.end_headers()
return
def do_GET(self):
if self.path.startswith("/songs/ID"):
self.load_cookie()
db=MediaDB()
ID = self.parseID(self.path)
song = db.getSong(ID)
self.send_response(200)
self.send_header('Access-Control-Allow-Origin', self.headers["Origin"])
self.send_header("Access-Control-Allow-Credentials", "true")
self.send_header("Content-Type", "text/plain")
self.cookie["sessionID"] = "4jjdd7ghhq"
self.send_cookie()
self.end_headers()
json_string = json.dumps(song)
self.wfile.write(bytes(json_string, "utf-8"))
elif self.path.startswith("/songs"):
self.getSongs()
return
else:
self.badPath()
return
def load_cookie(self):
if "Cookie" in self.headers:
self.cookie = cookies.SimpleCookie(self.headers["Cookie"])
else:
self.cookie = cookies.SimpleCookie()
return
def send_cookie(self):
for morsel in self.cookie.values():
self.send_header("Set-Cookie", morsel.OutputString())
return
================
我找不到了。如果有什么可以帮助我的话,我很感激你指出这一点。哦,顺便说一下,我的皮肤很厚,所以如果我做了什么蠢事-可以指出它。。。我得想办法学。哈!你知道吗
默认情况下,Chrome在处理本地文件时不支持cookies,正如我在你发布的屏幕截图中看到的那样。你知道吗
但是,您可以通过使用
enable-file-cookies
标志启动Chrome来改变这一点。你知道吗有关它的详细信息in this post。你知道吗
相关问题 更多 >
编程相关推荐