# coding=utf8 import requests from common.logger import Logger import logging class httpUtils: logger = Logger("../logs/http.log",logging.INFO,logging.INFO) def get(self,url,params={},headers={}): res = requests.get(url,data=params,headers=headers) self.logger.info("请求路径:" + res.request.url) headerStr = "" for headerKey in res.request.headers: headerStr = headerStr + " " + headerKey + ":" + res.request.headers[headerKey] self.logger.info("请求头信息:" + headerStr) self.logger.info("请求参数: " + res.request.body) resHeaderStr = "" for resHeaderKey in res.headers: resHeaderStr = resHeaderStr + " " + resHeaderKey + ":" + res.headers[resHeaderKey] self.logger.info("响应头信息:" + resHeaderStr) self.logger.info("返回结果: " + res.content.decode("utf-8")) return res def post(self,url,params={},headers={}): res = requests.post(url,data=params,headers=headers) self.logger.info("请求路径:"+res.request.url) headerStr = "" for headerKey in res.request.headers: headerStr =headerStr+ " " + headerKey + ":" + res.request.headers[headerKey] self.logger.info("请求头信息:" + headerStr) self.logger.info("请求参数: "+res.request.body) resHeaderStr = "" for resHeaderKey in res.headers: resHeaderStr =resHeaderStr+ " " + resHeaderKey + ":" + res.headers[resHeaderKey] self.logger.info("响应头信息:"+resHeaderStr) self.logger.info("返回结果: "+res.content.decode("utf-8")) return res