工作中我们经常用的可能都是body为json,要用接口上传下载文件怎么写呢?
1.上传
python用requests库,这个比较简单
f={'file':open('D:\\test_data\\summer_test_data_05.txt','rb')} #注意打开方式,二进制是b
upload_res=requests.post(url,upload_data,files=f,headers=header) #注意添加content-type头
jmeter上传

上图MIME就是content-type,可以根据要上传的文件类型百度,https://www.w3school.com.cn/media/media_mimeref.asp,如果要传其他参数,要在parameters下

2.下载
python
r = requests.get(url)
with open(path, 'wb') as f:
for i in r.iter_content(100): #100kb是缓冲区,如果是大文件,要设置缓冲区
f.write(i)
jmeter可以用Beanshell下载,利用prev.getResponseData()获取所有的响应
