import requests
get请求
url = 'http://api.nnzhp.cn/api/user/stu_info'
data = {'stu_name':'wyj'}
res = requests.get(url,data).text
print(res)
res.content # 代表下载
post请求
url = 'http://api.nnzhp.cn/api/user/login'
data = {'username':'niuhanyang','passwd':'aA123456'}
res = requests.post(url,data).json()
print(res)
入参是json
url = 'http://api.nnzhp.cn/api/user/add_stu'
data = {"name":"wyj","grade":"one","phone":13212345611}
res = requests.post(url,json=data).json()
print(res)
需要cookie
url = 'http://api.nnzhp.cn/api/user/gold_add'
data = {"stu_id":"100000150","gold":100}
cookie = {"niuhanyang":"0a6c1aacd55500e5c20a0ad95e7a099c"}
res = requests.post(url,data,cookies = cookie).json()
print(res)
需要header
url = 'http://api.nnzhp.cn/api/user/all_stu'
header = {'Referer':'http://api.nnzhp.cn/'}
res = requests.get(url,headers = header,verify=False).json()
print(res)
如果是https请求就加上verify=False
传文件到服务器上
url = 'http://api.nnzhp.cn/api/file/file_upload'
data = {'file':open('123.py','rb')}
res = requests.post(url,files = data).text
print(res)