#上传文件的post请求

#上传文件的post请求
#files={"files":open("test.txt","rb")}#普通上传
#files={"files":{"巧吧软件测试.jpg",open("巧吧软件测试.jpg","rb"),"image/jpg",{"refer":"localhost"}}}#设置文件名、文件类型和请求头
#files={{"field1",{"test.txt",open("test.txt","rb")}},}

import requests
url = "https://httpbin.org/post"

#第一种:普通上传
#files = {"files":open("test.txt","rb")}

#第二种:通过文件上传字符串等
#files = {"files":("test.txt","send hongtao")}

#第三种:自定义文件名、文件类型以及请求头(请求文件名称、文件路径、文件类型、文件请求头)
#files = {"files":open("巧吧软件测试.png","rb")}
#files = {"files":("巧吧软件测试.png",open("巧吧软件测试.png","rb"),"image/png")}

#第四种:传送多个文件
#files = [("field1",("test.txt",open("test.txt","rb"))),
# ("field2",("巧吧软件测试.png",open("巧吧软件测试.png","rb"),"image/png"))]

#r = requests.post(url,files=files)

#第五种:流式上传
with open("test.txt") as f:
r = requests.post(url,data=f)

print(r.headers)
print(r.text)

猜你喜欢

转载自www.cnblogs.com/smile2018tao/p/10171682.html