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;
}
5条答案
按热度按时间cclgggtu1#
当您提出请求时,请尝试选择
send and download
而不是send
(蓝色按钮)。https://www.getpostman.com/docs/responses
对于二进制响应类型,应选择
Send and download
,这将允许您将响应保存到硬盘.然后,您可以使用适当得查看器查看它.n3ipq98p2#
您可以只保存响应(pdf,doc等)的选项右侧的响应在 Postman 检查此图像
有关更多详细信息,请查看此
https://learning.getpostman.com/docs/postman/sending_api_requests/responses/
d6kp6zgx3#
如果终结点确实是指向.xls文件的直接链接,则可以尝试使用以下代码来处理下载:
您 * 应该 * 需要做的就是为auth令牌设置正确的名称并填写它。
示例用法:
h43kikqp4#
在postman中-您是否尝试过将标题元素“Accept”添加为“application/vnd.ms-excel”
bbuxkriu5#
对于UI,选择发送和下载按钮,而不是 Postman 中的发送按钮: