ImportRequestsurl='Http://127.0.0.1:8000/login'req= Requests.post (url+'?'+'username=fei&password=12')Print(req.text) #这里返回的是字符串>>>{"Code": 200,"msg":"Login Successful!"}
ImportRequestsurl='Http://127.0.0.1:8000/login'Data= {"username":"Fei","Password": 12}req=requests.post (url,data)Print(Req.text)>>>{"Code": 200,"msg":"Login Successful!"}
Import requests
url = ' Http://127.0.0.1:8000/login '
data = {"username": "Fei", "Password": 12}
req = requests.post (URL, data)
Print (Req.json ()) #返回字典格式, provided that the return must be a JSON string
>>>{' msg ': ' Login successful! ', ' Code ': $ #返回的肯定是字典, are unordered
#如何获取返回值里面的code
ImportRequestsurl="Http://127.0.0.1:8000/login"Data= {"username":"Fei","Password": 12}defGet_code (url,data): #传入链接地址, and Parameter res=requests.post (Url,data). JSON () #获取了返回值Print(RES)returnres['Code'The return value of]res is a dictionary that gets the code in the dictionary directly res "' Code '"Print(Get_code (URL, data))>>>{'Code': 200,'msg':'Login Successful!'}>>>200# prints the value of [' Code '] inside the return value
r = Requests.post (' Http://127.0.0.1:8000/add_stu ', json=data2) #请求报文为json类型的
Print (R.text)
#发带cookie的 Header
Sign = get_sign (url,data)
Cookie = {' sign ': sign}
Header = {' Touxinxi ': ' Hahahah '}
Data2 = {
"username": ' William ',
"Real_name": "The King of the continuous",
"Class": "Cancer",
"Phone": "19312345674"
}
url = "HTTP://127.0.0.1:8000/ADD_STU2"
R = Requests.post (url,json=data2,cookies=cookie,headers=header) #header里面传的时候不能有中文
Print (R.text)
#下面是上传文件的
File ={
' file_name ': Open (' hahah.py ', encoding= ' utf-8 ')
}
data = {"username": "Fei", ' pwd ': 12}
Url= "Http://127.0.0.1:8000/upload"
R = Requests.post (url,data,files=file)
Print (R.text)
Python Network programming trivia points