demo:
import requests
import json
class RunMain:
def __init__(self,url,data,method):
res = self.run_main(url,data,method)
def send_post(self,url, data):
res = requests.post(url=url, data=data).json()
return json.dumps(res, indent=2, sort_keys=True)
def send_get(self,url, data):
res = requests.get(url=url, data=data).json()
return json.dumps(res, indent=2, sort_keys=True)
def run_main(self,url, data, method):
res = None
if method == 'GET':
self.res = self.send_get(url, data)
else:
self.res = self.send_post(url, data)
return res
if __name__ =='__main__':
url = 'http://hc1-test.lifit.com.cn/api/hcchangepassword'
data = {
'uid': '151632',
'oldpassword': '123456',
'newpassword': '111111'
}
run = RunMain(url,data,'POST')
print (run.res)