关于在pycharm中利用 requests 库 调用接口: 比如:get请求
import requests
url = 'http://v.juhe.cn/laohuangli/d?'
dates = {'date': '2021-07-15', 'key': 'XXXX'}
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.193 Safari/537.36'}
res = requests.get(url, dates, headers=headers)
print('响应状态码:', res.status_code)
print('请求头信息:', res.request.headers)
print('响应正文1:', res.json())
print('响应正文2:', res.text)
注册-登录-充值接口
registered_url = 'http://test.lemonban.com/futureloan/mvc/api/member/register'
registered_date = {'mobilephone': '1397213680', 'pwd': '123456'}
registered_res = requests.get(registered_url, registered_date)
print('响应正文:', registered_res.json())
print('响应正文:', registered_res.status_code)
login_url = 'http://test.lemonban.com/futureloan/mvc/api/member/login'
login_date = {'mobilephone': '1397213680', 'pwd': '123456'}
header = {'User-Agent':
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.193 Safari/537.36'}
login_res = requests.post(login_url, data=login_date, headers=header)
print('响应报文:', login_res.json())
print('响应状态码:', login_res.status_code)
print('响应头:', login_res.headers)
print('请求头:', login_res.request.headers)
print('**cookies:**', login_res.cookies)
topup_url = 'http://test.lemonban.com/futureloan/mvc/api/member/recharge'
topup_data = {'mobilephone': '1397213680', 'amount': '1000'}
topup_res = requests.post(topup_url, topup_data)
print('cookies values:', topup_res.cookies)
print('响应正文:', topup_res.json())
print('响应状态码:', topup_res.status_code)
响应的结果是:
|