接口请求的封装 发表于 2024-03-18 | 分类于 框架封装 字数统计: 99 字 | 阅读时长 ≈ 1 分钟 进行请求接口的封装 123456789101112131415161718class APIClient: def __init__(self, base_url): # 设置基础访问地址 self.base_url = base_url # 保持会话 self.session = requests.session() def get(self, url, **kwargs): return self.session.request('GET', self.base_url+url, **kwargs) def post(self, url, data=None, json=None, **kwargs): return self.session.request('POST', self.base_url+url, data, json, **kwargs) def put(self, url, data=None, **kwargs): return self.session.request('PUT', self.base_url+url, data, **kwargs) def delete(self, url, **kwargs): return self.session.request('DELETE', self.base_url+url, **kwargs) ------------- End -------------