ImportRequests
1, HairGetRequest
URL =' Http://api.nnzhp.cn/api/user/stu_info '
data = {' Stu_name ':'Little Black'}#Request Data
req = Requests.get (url,params=data)#HairGetRequest
Print (Req.json ())#Dictionary
Print (Req.text)#string,JSONstring
What's the return?
What is the returned type?
How does the Chinese do?
2, HairPostRequest
URL =' Http://api.nnzhp.cn/api/user/login '
data = {' username ':' Niuhanyang ',' passwd ':' aA123456 '}#Request Data
req = Requests.post (url,data)#SendPostRequest
Print (Req.json ())
3, enter the parameter isJsontype of
ImportRandom
Phone=random.randint (10000000000,99999999999)
Url=' Http://api.nnzhp.cn/api/user/add_stu '
data = {
"Name":"Small1 ",
"Grade":"Scorpio",
"Phone":p Hone,
"Sex":"male",
"Age": 28,
"Addr":"Beihai Road, Jiyuan, Henan province +number"
}
req = Requests.post (url,json=data)
Print (Req.json ())
4, addCookies
URL =' Http://api.nnzhp.cn/api/user/gold_add '
data = {' stu_id ': 468,' Gold ': 10000}
DJL = {' Niuhanyang ':' 337ca4cc825302b3a8791ac7f9dc4bc6 '}
req = Requests.post (URL,DATA,COOKIES=DJL)
Print (Req.json ())
5, addHeader
URL =' Http://api.nnzhp.cn/api/user/all_stu '
Header = {
' Referer ':' http://api.nnzhp.cn/'
}
req = Requests.get (Url,headers=header)
Print (Req.json ())
6, uploading Files
Url=' Http://api.nnzhp.cn/api/file/file_upload '
data = {
' file ': Open (R ' C:\Users\bjniuhanyang\Desktop\Figure\6bd9026dt935575932465&690.jpg ',' RB ')
}
req= Requests.post (Url,files=data)
Print (Req.json ())
7, download files
URL =' Http://up.mcyt.net/?down/46779.mp3 '
req = requests.get (URL)
FW = Open (' Aaa.mp3 ',' WB ')
Fw.write (req.content)
Python--requests Module