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()类里面的函数调用