python_30期自动化【类的封装】
2021-01-14 03:14
标签:requests assm def ssm python 封装 报文 @class eth python_30期自动化【类的封装】 标签:requests assm def ssm python 封装 报文 @class eth 原文地址:https://www.cnblogs.com/zhang-ping1205/p/12943940.htmlimport requests
class HttpRequests:
# def https_requests(login_url,data,http_method):#调用;提高复用性
# @staticmethod
# def https_requests(login_url, data, http_method=‘POST‘):
@classmethod
def https_requests(cls,login_url, data, http_method=‘POST‘):
# def https_requests(self,login_url, data, http_method=‘POST‘):
# login_url = "http://www.tuling123.com/openapi/api"
# data = {
# "key": "ec961279f453459b9248f0aeb6600bbe",
# "info": "你好"
# } # 字典格式,单独提出来,方便参数的添加修改等操作(二选一的方式)
if http_method.upper()==‘GET‘:
res = requests.get(login_url, data)
else:#执行的是post请求
res = requests.post(login_url, data)
print("post请求的json格式报文", res.json())
login_url = "http://www.tuling123.com/openapi/api"
data = {
"key": "ec961279f453459b9248f0aeb6600bbe",
"info": "你好"
} # 字典格式,单独提出来,方便参数的添加修改等操作
HttpRequests().https_requests(login_url,data,‘GET‘)#HttpRequests()类里面的函数调用
文章标题:python_30期自动化【类的封装】
文章链接:http://soscw.com/index.php/essay/41600.html