基于BaseHTTPServer写的代理Post方法源码(只做参考,性能待优化)
来源:互联网 发布:考研英语网络课程 编辑:程序博客网 时间:2024/06/06 02:29
#coding=utf8from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServerimport gzipfrom StringIO import StringIO#import timeimport loggingimport syslogging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', datefmt='%a, %d %b %Y %H:%M:%S', filename='proxy.log', filemode='w')class proxyHandler(BaseHTTPRequestHandler): def do_POST(self): try: path = self.path logging.debug(path) if self.headers["content-encoding"]=="gzip": logging.debug(self.headers) #获取post提交的数据 datas =gzip.GzipFile(fileobj=StringIO(self.rfile.read())).read() logging.debug(datas) self.wfile.write(datas+path) sys.stdout.write(datas) except Exception,e: logging.error(e) finally: self.finish() def do_CONNECT(self): pass def do_GET(self): pass def test(): host='127.0.0.1' port=8888 try: server = HTTPServer((host, port), proxyHandler) print 'Welcome to the Server HTTP On %s Port %d...' %(host,port) server.serve_forever() except KeyboardInterrupt,e: logging.error(e) #print '^C received, shutting down server' server.socket.close()if __name__ == '__main__': test()
通过logging模块记录,日志信息;这个方法是用来获取头文件包含json数据,但使用gzip编码的数据操作的post方法!
阅读全文
0 0
- 基于BaseHTTPServer写的代理Post方法源码(只做参考,性能待优化)
- python的BaseHTTPServer模块接收post请求
- HttpClient中的 Get 和 Post (一个待优化的WebUtil)
- 基于Oracle PLSQL的存储过程性能优化方法案例
- HBase性能优化方法总结(3):写表操作
- HBase性能优化方法总结(二):写表操作
- HBase性能优化方法总结(二):写表操作
- HBase性能优化方法总结(3):写表操作
- HBase性能优化方法总结(二):写表操作
- HBase性能优化方法总结(二):写表操作
- python--模拟POST登陆请求(待优化)
- SQL的性能监控优化参考
- 自适应控制---模型参考自适应控制(一)基于局部参数最优化的设计方法(MIT方案)
- 性能优化的方法?
- 性能优化的方法
- Linux性能优化参考
- 性能优化经验参考
- tomcat8性能优化参考
- java中的内部类创建对象方法
- step by step
- android 文件目录权限
- 从K近邻算法、距离度量谈到KD树、SIFT+BBF算法
- 使用template (模板引擎写的demo)
- 基于BaseHTTPServer写的代理Post方法源码(只做参考,性能待优化)
- 第二章 js输出、语句、变量、注释
- 自定义Toast实现各种炫酷效果
- 在unity3d中接受MQTT消息协议数据C# .net,M2Mqtt
- iOS cell与cell.contentView的区别
- geometry-api-java 学习笔记(三)多点 multipoint
- qt线程
- lua判断点在任意多边形内部
- Android APK加固完善篇