python_30期自动化【类的封装】

时间:2020-05-23 20:05:19   收藏:0   阅读:49
import 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()类里面的函数调用
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!