1 import requests
2 class Interface_Request:
3
4 def __init__(self,url,mobilephone,pwd):
5 '''login参数初始化'''
6 self.url = url
7 self.dict = {'mobilephone':mobilephone,'pwd':pwd}
8
9 def http_request(self,way):
10 '''login接口请求'''
11 if way=='get':
12 return requests.get(self.url,self.dict).headers
13 elif way=='post':
14 while(True):
15 Question = input('是否使用json传递?请输入y/n')
16 if Question=='y' or Question=='n':
17 if Question=='y':
18 return requests.post(self.url,json=self.dict).headers
19 elif Question == 'n':
20 return requests.post(self.url,self.dict).headers
21 else:
22 print('请重新输入!')
23 continue
24 if __name__ == '__main__':
25 login = Interface_Request('URL地址','手机号','密码')
26 print('get传参:',login.http_request('get'))
27 print('post传参:',login.http_request('post'))