GET
代码
import requests
#get请求
url = 'http://httpbin.org/get'
data = {'Lula': 'Study', 'Domain': 'coding.lula.fun'}
#get是使用get方式请求url,字典类型的data不需要额外处理
response = requests.get(url, data)
print(response.text)
运行
POST
代码
import requests
#post请求
url = 'http://httpbin.org/post'
data = {'Lula': 'Study', 'Domain': 'coding.lula.fun'}
response = requests.post(url, data)
print(response.json())
运行
返回数据
{'args': {}, 'data': '', 'files': {}, 'form': {'Domain': 'coding.lula.fun', 'Lula': 'Study'}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Content-Length': '26', 'Content-Type': 'application/x-www-form-urlencoded', 'Host': 'httpbin.org', 'User-Agent': 'python-requests/2.22.0'}, 'json': None, 'origin': '47.52.194.178, 47.52.194.178', 'url': 'https://httpbin.org/post'}