发布时间:2019-09-22 07:41:01编辑:auto阅读(3561)
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
import urllib2
# 在 urllib2 上注册 http 流处理句柄
register_openers()
# 开始对文件 "DSC0001.jpg" 的 multiart/form-data 编码
# "image1" 是参数的名字,一般通过 HTML 中的 <input> 标签的 name 参数设置
# headers 包含必须的 Content-Type 和 Content-Length
# datagen 是一个生成器对象,返回编码过后的参数
datagen, headers = multipart_encode({"image1": open("DSC0001.jpg", "rb")})
# 创建请求对象
request = urllib2.Request("http://localhost:5000/upload_image", datagen, headers)
# 实际执行请求并取得返回
print urllib2.urlopen(request).read()data = { 'name': 'nginx'}
files = {'file': open("abc.csv", 'rb')}
response = requests.post(url, data=data, files=files)
上一篇: 凸优化:python解决凸优化问题
下一篇: XXTEA加解密as3和python分别
54203
40963
35477
31097
25988
25723
24179
19726
15771
15233
2020°
1856°
1943°
2042°
2029°
2211°
2166°
1986°
2063°
2048°