import http.client
import json
标签:body,__,封装,headers,python,res,self,url,https From: https://www.cnblogs.com/kobeBryant-8/p/17767206.html
class HTTPS_Connection:
def __init__(self, res_type, body, url, api_path, headers):
self.res_type = res_type # 接口请求类型
self.body = body # 请求参数
self.url = url # 请求服务地址
self.path = api_path # 接口路由
self.headers = headers # 请求头
def https_res(self):
conn = http.client.HTTPSConnection(self.url)
body = json.dumps(self.body)
conn.request(method=self.res_type, url=self.path, body=body, headers=self.headers)
res = conn.getresponse()
response = res.read()
print('接口返回结果:%s' % response.decode('utf-8'))
return response.decode('utf-8')
if __name__ == '__main__':
pass