pra*_*net 148 rest rest-client postman advanced-rest-client
我正在为该API提供API-Endpoint和Authtoken
所述API用于.XLS报告下载,如何使用(如果可能)POSTMAN查看下载的.xls文件?
如果使用邮递员是不可能的,那么我应该寻找的其他程序化方法是什么?
Jak*_*ake 316
提出请求时,请尝试选择"发送和下载"而不是"发送".(蓝色按钮)
https://www.getpostman.com/docs/responses
"对于二进制响应类型,您应该选择"发送和下载",这样您就可以将响应保存到硬盘中.然后您可以使用适当的查看器查看它."
Aki*_*_MJ 21
您可以通过邮递员响应右侧的选项保存响应(pdf,doc等)检查此图像

有关更多详细信息,请检查此
https://learning.getpostman.com/docs/postman/sending_api_requests/responses/
如果端点确实是指向.xls文件的直接链接,则可以尝试以下代码来处理下载:
public static boolean download(final File output, final String source) {
try {
if (!output.createNewFile()) {
throw new RuntimeException("Could not create new file!");
}
URL url = new URL(source);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// Comment in the code in the following line in case the endpoint redirects instead of it being a direct link
// connection.setInstanceFollowRedirects(true);
connection.setRequestProperty("AUTH-KEY-PROPERTY-NAME", "yourAuthKey");
final ReadableByteChannel rbc = Channels.newChannel(connection.getInputStream());
final FileOutputStream fos = new FileOutputStream(output);
fos.getChannel().transferFrom(rbc, 0, 1 << 24);
fos.close();
return true;
} catch (final Exception e) {
e.printStackTrace();
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
所有你应该需要做的是为验证令牌设置了正确的名称,并填写好。
用法示例:
download(new File("C:\\output.xls"), "http://www.website.com/endpoint");
Run Code Online (Sandbox Code Playgroud)