get
import requests # get url = 'http://api.nnzhp.cn/api/user/stu_info' d = {'stu_name':'矿泉水'} r = requests.get(url,d)#发get请求 print('r.json',r.json())#返回一个字典 print('r.text',r.text)#返回一个字符串 print('r.content',r.content)#返回的是bytes类型
post
url = 'http://api.nnzhp.cn/api/user/login' data = {'username':'niuhanyang','passwd':'aA123456'} r = requests.post(url,data) print(r.text)
上传文件
url = 'http://api.nnzhp.cn/api/product/add' r = requests.post(url,files={'file':open('文件名','rb')}) print(r.text)