为什么客户端不接受我的 WebSocket 响应握手?
我使用 Chrome 14。这是我的 python websocket 服务器代码片段:
global guid
key = hashlib.sha1(headers['Sec-WebSocket-Key']+guid).digest()
key.encode('iso-')
headers['Sec-WebSotycket-Accept'] = base64.b64encode(key)
print headers['Sec-WebSocket-Accept']
handshake = '\
HTTP/1.1 101 Switching Protocols\r\n\
Upgrade: %s\r\
Connection: %s\r\
Sec-WebSocket-Accept: %s\r\
Sec-WebSocket-Protocol: base64\r\
' %(headers['Upgrade'],headers['Connection'],headers['Sec-WebSocket-Accept'])
try:
self.conn.send(handshake)
except Exception as e:
print e
为什么 Chrome 客户端不接受此服务器发送握手?
Request URL:ws://127.0.0.1:1234/
Request Headers
Connection:Upgrade
Host:127.0.0.1:1234
Sec-WebSocket-Key:xuV2xuiXxqL4Hwcxjg9dJA==
Sec-WebSocket-Origin:null
Sec-WebSocket-Version:8
Upgrade:websocket
(Key3):00:00:00:00:00:00:00:00
I use Chrome 14. This is my python websocket server code snippet:
global guid
key = hashlib.sha1(headers['Sec-WebSocket-Key']+guid).digest()
key.encode('iso-')
headers['Sec-WebSotycket-Accept'] = base64.b64encode(key)
print headers['Sec-WebSocket-Accept']
handshake = '\
HTTP/1.1 101 Switching Protocols\r\n\
Upgrade: %s\r\
Connection: %s\r\
Sec-WebSocket-Accept: %s\r\
Sec-WebSocket-Protocol: base64\r\
' %(headers['Upgrade'],headers['Connection'],headers['Sec-WebSocket-Accept'])
try:
self.conn.send(handshake)
except Exception as e:
print e
Why does the Chrome client not accept this server send handshake?
Request URL:ws://127.0.0.1:1234/
Request Headers
Connection:Upgrade
Host:127.0.0.1:1234
Sec-WebSocket-Key:xuV2xuiXxqL4Hwcxjg9dJA==
Sec-WebSocket-Origin:null
Sec-WebSocket-Version:8
Upgrade:websocket
(Key3):00:00:00:00:00:00:00:00
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它可能是你的服务器代码的第 4 行吗?您的密钥“Sec-WebSotycket-Accept”看起来拼写错误。
Could it be line 4 of your server code? Your key "Sec-WebSotycket-Accept" looks misspelled.