目录
1.接口数据获取
1)打开F12或者使用抓包工具获取接口数据
2)Request Method:POST
Content-Type:application/x-www-form-urlencoded
2. 新建Http Request并填写基础数据
1)填写 Web Server:protocol,ip,port
2)填写 Http Request:Method,Path,endcoding
3)填写 Parameters
4)勾选Follow Redirects、Use KeepAlive
3.Content-Type处理
如果HTTP Header Manager已设置全局Content-Type,并且与当前导出接口类型不一致,则需要再该接口请求是重新设置Content-Type:application/x-www-form-urlencoded
4.导出文件后置处理器
由于导出接口执行后要存放导出文件,因此需要BeanShell PostProcessor后置处理器设置文件的存放路径及保存名称
import java.io.*;
// 获取请求返回的数据,通过prev方法获取上个请求的返回
byte[] result = prev.getResponseData();
// 设置文件导出存放路径及保存的文件名
String file_name = "D:/export/default-price-export.xls";
File file = new File(file_name);
FileOutputStream out = new FileOutputStream(file);
out.write(result);
out.close();