Python中BaseHttp模块的响应中的HTTP版本
我正在用Python运行一个基于BaseHttp的服务器。
我收到了一个来自客户端的请求,这个请求是基于HTTP/1.1的。
但是,当我试图给客户端发送我的回应时,客户端拒绝接受我的回应。
经过进一步分析,我发现我发送的HTTP版本是HTTP/1.0。
不过,我不知道这个版本是怎么设置的。
客户端那边的错误信息是:
Original message: not well-formed (invalid token): line 2, column 4
Response
HTTP/1.0 200 OK
Server: BaseHTTP/0.3 Python/2.7.5
Date: Wed, 30 Jul 2014 15:11:42 GMT
Content-type: application/soap+xml; charset=utf-8
Content-length: 823
我设置头信息的方式是:
self.send_response(200)
self.send_header("Content-type", "application/soap+xml; charset=utf-8")
self.send_header("Content-length", content_length)
self.end_headers()
1 个回答
7
在你的处理类上设置 protocol_version
属性:
handler.protocol_version = 'HTTP/1.1'
这需要你设置一个 Content-Length
头部,这个你已经做到了。