1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| #!/usr/bin/env python # coding:utf-8
import tornado.ioloop import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self): print("method: ", self.request.method) print("Content-Type: ", self.request.headers.get("Content-Type", "No-Content-Type")) print("uri: ", self.request.uri) print("path: ", self.request.path) print("argument: ", self.request.arguments) print("body: ", self.request.body)
def post(self): print("method: ", self.request.method) print("Content-Type: ", self.request.headers.get("Content-Type", "No-Content-Type")) print("uri: ", self.request.uri) print("path: ", self.request.path) print("argument: ", self.request.arguments) print("body: ", self.request.body)
def head(self): """ 主要测试file :return: """ print("method: ", self.request.method) print("Content-Type: ", self.request.headers.get("Content-Type", "No-Content-Type")) print("uri: ", self.request.uri) print("path: ", self.request.path) print("argument: ", self.request.arguments) print("body: ", self.request.body) print("body str: ") print(self.request.body.decode())
print('-' * 20) print("file:") for _, l in self.request.files.items(): print('-' * 10) for f in l: content = f.body filename = str(f.filename) print("filename: ", filename) print("content: ", content)
application = tornado.web.Application([ (r"/main", MainHandler), ])
if __name__ == "__main__": application.listen(5001) tornado.ioloop.IOLoop.instance().start()
|