python - 接口自动化测试 - HttpRequest - 接口测试类封装
# -*- coding:utf-8 -*- ''' @project: ApiAutoTest @author: Jimmy @file: http_request.py @ide: PyCharm Community Edition @time: 2018-12-20 11:38 @blog: https://www.cnblogs.com/gotesting/ ''' import requests class HttpRequest: def __init__(self,method,url,data=None,cookies=None,headers=None): try: if method == 'get': self.response = requests.get(url=url,params=data,cookies=cookies,headers=headers) elif method == 'post': self.response = requests.post(url=url,data=data,cookies=cookies,headers=headers) elif method == 'detele': self.response = requests.delete(url=url,data=data,cookies=cookies,headers=headers) except Exception as e: raise e def get_status_code(self): return self.response.status_code def get_text(self): return self.response.text def get_json(self): return self.response.json() def get_cookies(self): return self.response.cookies