我有一个 API 端点和该 API 的授权令牌。
上述 API 用于.xls
报告下载,我如何.xls
使用(如果可能)Postman查看下载的文件?
如果无法使用Postman,我应该寻找哪些其他编程方式?
我有一个 API 端点和该 API 的授权令牌。
上述 API 用于.xls
报告下载,我如何.xls
使用(如果可能)Postman查看下载的文件?
如果无法使用Postman,我应该寻找哪些其他编程方式?
尝试选择send and download
而不是send
在您提出请求时进行选择。(蓝色按钮)
https://www.getpostman.com/docs/responses
“对于二进制响应类型,您应该选择Send and download
哪一种可以让您将响应保存到硬盘。然后您可以使用适当的查看器查看它。”
您可以通过邮递员响应右侧的选项保存响应(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;
}
您需要做的就是为身份验证令牌设置正确的名称并填写它。
示例用法:
download(new File("C:\\output.xls"), "http://www.website.com/endpoint");
在邮递员中-您是否尝试过将标题元素“接受”添加为“应用程序/vnd.ms-excel”