Requests
支持HTTP连接保持和连接池,支持使用cookie保持会话,支持文件上传,支持自动确定响应内容的编码,支持国际化的 URL 和 POST 数据自动编码。
Requests
的底层实现其实就是urllib3
1 Requests
安装
pip install requests
2 Requests
开源地址
https://github.com/kennethreitz/requests
3 Requests
中文文档
http://docs.python-requests.org/zh_CN/latest/index.html
4 Requests
get 请求
response = requests.get(url)
import requests
response = requests.get("http://39.100.133.182/py-test.php?type=1")
response.text #查看响应内容
response.content #查看响应内容,字节流数据
response.url #查看完整url地址
response.status_code #查看响应码
data = response.json() #常用-返回json格式数据
print(data)
4 Requests
post 请求
response = requests.post(url, json = params , headers = headers)
import requests
url = "http://39.100.133.182/py-test.php"
params = {
"a" : 1,
"b" : 2
}
response = requests.post(url, json = params)
res = response.json()
报告结果截图如下
-- Github
地址 https://github.com/mingyuanHub/python-game-test
![](https://img.haomeiwen.com/i19009365/3fff70dc9d81c9ed.png)
网友评论