import requests
import json
classRunMain:def__init__(self,url,method,data=None):
self.run_main(url,method,data=None)defsend_get(self,url,data=None):print(data)
res = requests.get(url=url,data=data).text
print('res=%s'%res,type(res))return res
defsend_post(self,url,data=None):
res = requests.post(url=url,data=data).text
res = json.loads(res)#上面两句可以合并为一句 res = requests.post(url=url, data=data).json()# return json.dumps(res, indent=2, sort_keys=True) #字典转字符串序列化可以这么写return res
defrun_main(self,url,method,data=None):if method =='GET':
res = self.send_get(url,data)else:
res = self.send_post(url,data)return res
if __name__ =='__main__':
url ='http://127.0.0.1:8001/login/'
data ={'username':'jonathantfff','password':'jack666666',}
rm = RunMain(url,'POST',data=data)