256

我有一个 API 端点和该 API 的授权令牌。

上述 API 用于.xls报告下载,我如何.xls使用(如果可能)Postman查看下载的文件?

如果无法使用Postman,我应该寻找哪些其他编程方式?

4

4 回答 4

574

尝试选择send and download而不是send在您提出请求时进行选择。(蓝色按钮)

https://www.getpostman.com/docs/responses

“对于二进制响应类型,您应该选择Send and download哪一种可以让您将响应保存到硬盘。然后您可以使用适当的查看器查看它。”

于 2016-08-16T17:54:45.977 回答
25

您可以通过邮递员响应右侧的选项保存响应(pdf,doc等)检查此图像 邮递员保存回复

有关更多详细信息,请查看此

https://learning.getpostman.com/docs/postman/sending_api_requests/responses/

于 2019-07-29T06:56:46.777 回答
9

如果端点确实是 .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");
于 2016-08-16T16:40:28.730 回答
4

在邮递员中-您是否尝试过将标题元素“接受”添加为“应用程序/vnd.ms-excel”

于 2016-08-16T17:19:12.570 回答