标签:result login ade 上传文件 pass div inf color pytho
1 import requests 2 3 #get请求 4 url = ‘http://127.0.0.0/api/user/stu_info‘ 5 data = {"stu_info":"xiaoming"} 6 result = requests.get(url,data).text #text方法返回的是字符串格式的返回值 7 result = requests.get(url,data).json() #json()返回的是字典格式的返回值 8 print(result) 9 10 #post请求 11 url = ‘http://127.0.0.0/api/user/login‘ 12 data = {"username":"xmb","password":"123456"} 13 result = requests.post(url,data).text #text方法返回的是字符串格式的返回值 14 result = requests.post(url,data).json() #json()返回的是字典格式的返回值 15 print(result) 16 17 #入参是json 18 url = ‘http://127.0.0.0/api/user/add_stu‘ 19 data = {"name":"xmb123","grade":"一班","phone":18600000000} 20 result = requests.post(url,json=data).json() #接口入参要求是json类型 21 print(result) 22 23 #接口需要带cookie的 24 cookie = {"xmb":"f791d8401b62ba23ec55ebeffe85f2d0"} 25 url = "http://127.0.0.0/api/user/gold_add" 26 data = {"stu_id":"1001000","gold":"1000"} 27 result = requests.post(url,data,cookies=cookie).text 28 print(result) 29 30 #接口需要带header的 31 url = ‘http://127.0.0.0/api/user/all_stu‘ 32 header = {"Referer":"http:baidu.com"} 33 result = requests.get(url,header=header).text 34 print(result) 35 36 #上传文件接口 37 url = ‘http://127.0.0.0/file/file_upload‘ 38 result = requests.post(url,files = {"file":open("request.py","rb")}).text 39 print(result)
标签:result login ade 上传文件 pass div inf color pytho
原文地址:https://www.cnblogs.com/xumb/p/11888124.html