一 文件上传
1 代码
import requests
#favicon.ico需要和当前脚本在同一目录下。
files = {'file': open('favicon.ico', 'rb')}
r = requests.post("http://httpbin.org/post", files=files)
print(r.text)
2 运行结果
E:\WebSpider\venv\Scripts\python.exe E:/WebSpider/3_2_2.py
{
"args": {},
"data": "",
"files": {
"file": "data:application/octet-stream;base64,AAABAAIAEBAAAAEAIAAoBQAAJgAAACAgAAABACAAKBQAAE4
},
"form": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Connection": "close",
"Content-Length": "6665",
"Content-Type": "multipart/form-data; boundary=ea9414f1b8ae442f768c08b6a62b8082",
"Host": "httpbin.org",
"User-Agent": &#