我想用python做一个HTTP服务器,来托管我的网站。我已经实现了do\u GET()方法,它工作得很好,但是当我尝试POST方法时,服务器在我重新加载页面之前没有响应。然后它醒来了,努力完成帖子,但意识到连接已经结束。之后,它为GET方法提供服务(因为我重新加载了页面),并继续正常运行。在
我在客户端使用jQuery,但我也尝试了html表单。即使我在另一个浏览器中打开这个页面也没有什么变化,所以在服务器端一定是个例外。在
以下是客户端javascript:function Send()
{
jQuery.post("address", "Blah!", function (data) {
//get response
alert(data);
});
}
下面是服务器代码(我使用的是python3.3.4):
^{pr2}$
这是来自服务器的日志:10.175.72.200 - - [01/Apr/2014 19:11:26] "GET / HTTP/1.1" 200 -
Data: Blah!
10.175.72.200 - - [01/Apr/2014 19:11:47] "POST /address HTTP/1.1" 200 -
----------------------------------------
Exception happened during processing of request from ('10.175.72.200', 2237)
Traceback (most recent call last):
File "C:\Python33\lib\socketserver.py", line 306, in _handle_request_noblock
self.process_request(request, client_address)
File "C:\Python33\lib\socketserver.py", line 332, in process_request
self.finish_request(request, client_address)
File "C:\Python33\lib\socketserver.py", line 345, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Python33\lib\socketserver.py", line 666, in __init__
self.handle()
File "C:\Python33\lib\http\server.py", line 400, in handle
self.handle_one_request()
File "C:\Python33\lib\http\server.py", line 388, in handle_one_request
method()
File "C:\Users\Jirek\Desktop\Server\server.py", line 45, in do_POST
self.wfile.write(response) #send response
File "C:\Python33\lib\socket.py", line 317, in write
return self._sock.send(b)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
----------------------------------------
10.175.72.200 - - [01/Apr/2014 19:11:47] "GET / HTTP/1.1" 200 -
你可以看到,第一行是经典的GET请求。然后我从浏览器中调用POST,在重新加载之前什么都没有发生。此时,服务器将写入日志的其余部分。在