1 """HTTP及requests库方法"""
2
3
4 import requests
5
6 # requests库head()方法:得到头部信息
7 r = requests.head("http://httpbin.org/get")
8
9 print(r.headers)
10 print(r.text) # 空
11
12
13 # requests库post()方法:向表单增加信息
14 payload = {‘key1‘: ‘value1‘, ‘key2‘:‘value2‘}
15 r = requests.post("http://httpbin.org/post", data = payload)
16 print(r.text)
17 # requests库post()方法:向data增加信息
18 r = requests.post("http://httpbin.org/post", data = "ABC")
19 print(r.text)
20
21 # requests库put()方法:覆盖原有数据
22 payload = {‘key1‘: ‘value1‘, ‘key2‘:‘value2‘}
23 r = requests.put("http://httpbin.org/put", data = payload)
24 print(r.text)