zkwgpp 2020-06-04
"""HTTP及requests库方法""" import requests # requests库head()方法:得到头部信息 r = requests.head("http://httpbin.org/get") print(r.headers) print(r.text) # 空 # requests库post()方法:向表单增加信息 payload = {‘key1‘: ‘value1‘, ‘key2‘:‘value2‘} r = requests.post("http://httpbin.org/post", data = payload) print(r.text) # requests库post()方法:向data增加信息 r = requests.post("http://httpbin.org/post", data = "ABC") print(r.text) # requests库put()方法:覆盖原有数据 payload = {‘key1‘: ‘value1‘, ‘key2‘:‘value2‘} r = requests.put("http://httpbin.org/put", data = payload) print(r.text)