我有一个API端点和该API的授权令牌。
所述API用于下载.xls报告。如果可能的话,我如何使用Postman查看已下载的.xls文件?
如果无法使用Postman,我应该寻找哪些其他编程方式?
所述API用于下载.xls报告。如果可能的话,我如何使用Postman查看已下载的.xls文件?
如果无法使用Postman,我应该寻找哪些其他编程方式?
发送并下载
而不是发送
,当您发出请求时(蓝色按钮)。
https://www.getpostman.com/docs/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;
}
你只需要做的是为认证令牌设置正确的名称并填写它。
使用示例:
download(new File("C:\\output.xls"), "http://www.website.com/endpoint");
在Postman中,您是否尝试将头元素“Accept”添加为“application/vnd.ms-excel”?