# import Urllib.request
# import JSON
Import requests
# url = ' http://api.nnzhp.cn/api/user/stu_info?stu_name=ybq123 '
# res = urllib.request.urlopen (URL) # Send request
# res_new = Res.read (). Decode () # Get Results
# Print (res_new)
# Send a GET request
# res = requests.get (URL) # send GET request
# print (res.text) # Get Results
# Print (Type (res.text))
# Print (Json.loads (res.text))
# Print (Res.json ()) # Gets the result directly is the dictionary, must return is the JSON string, can use the JSON () method
# Send a POST request
# url = ' Http://api.nnzhp.cn/api/user/login '
# data = {' username ': ' Niuhanyang ', ' passwd ': ' aA123456 '}
# req = requests.post (URL, data) # sends a POST request, the first parameter is the URL, the second parameter is the requested data
# Print (Req.json ())
# Print (Req.text)
#
# url1 = ' Http://api.nnzhp.cn/api/user/user_reg '
# data = {
# ' username ': ' Wangsilei ',
# ' pwd ': ' wang123a ',
# ' cpwd ': ' wang123a '
# }
# res = Requests.post (URL1, data)
# Print (Res.text)
# The import parameter is JSON
# url = ' Http://api.nnzhp.cn/api/user/add_stu '
# data = {
# ' name ': ' Wang Silei ',
# ' Grade ': ' Sagittarius ',
# ' phone ': 18033555656
# }
# req = requests.post (URL, json=data)
# Print (Req.json ())
# Add a cookie
# 8b7d1b49fc8be17afe68bc67c82ea98b
# url = ' Http://api.nnzhp.cn/api/user/gold_add '
# data = {
# ' stu_id ': 231,
# ' Gold ': 10000
# }
# cookie = {' Niuhanyang ': ' 8b7d1b49fc8be17afe68bc67c82ea98b '}
# req = requests.post (URL, data, Cookies=cookie)
# Print (Req.json ())
# Add Header's
url = ' Http://api.nnzhp.cn/api/user/all_stu '
Header = {' Referer ': ' http://api.nnzhp.cn/'}
req = Requests.get (URL, headers=header)
Print (Req.json ())
# Upload Files
# url = ' Http://api.nnzhp.cn/api/file/file_upload '
# with Open (R ' C:\Users\wangsilei\Music\ Phoenix legend \ Phoenix Legends-Fury of Love. mp3 ', ' RB ') as F:
# r = requests.post (URL, files={' file ': F})
# Print (R.json ())
# download file
# url = ' http://img.lelezone.com/thumb/p/imgs/20/20390/20390_10.jpg '
# r = Requests.get (URL)
# print (r.status_code) # Get the requested status code
# print (r.content) # Gets the returned result in binary format
# with open (' dog.jpg ', ' WB ') as F:
# F.write (r.content)
# Save Web Page
# url = ' http://www.nnzhp.cn/archives/630 '
# res = requests.get (URL)
# with open (' nnzhp_630.html ', ' WB ') as F:
# F.write (res.content)
python--Network Programming