我有以下服务器代码。它创建python http服务器。在
现在,它只接收客户端发送的信息,但我希望能够存储客户端发送到服务器的任何内容。在
例如,若客户机发送“helloworld”,则“helloworld”将出现在服务器端,但它只显示它。我希望能够将接收到的字符串存储在某个变量中。在
比如说。。。。字符串str,那么如果我打印str,那么它会打印“Hello World”。在
有人能告诉我怎么做吗?在import time
import BaseHTTPServer
HOST_NAME = '127.0.0.1' # !!!REMEMBER TO CHANGE THIS!!!
PORT_NUMBER = 8868 # Maybe set this to 9000.
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_HEAD(s):
s.send_response(200)
def do_GET(s):
"""Respond to a GET request."""
s.send_response(200)
if __name__ == '__main__':
server_class = BaseHTTPServer.HTTPServer
httpd = server_class((HOST_NAME, PORT_NUMBER), MyHandler)
print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER)
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()
print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER)
每当我运行此服务器,并单击按钮将内容发送到此服务器时,服务器将显示以下内容。在
^{pr2}$
我希望能够将GET id=497 blah blah存储到函数内部的变量中,作为字符串。在