如何从postman中的API下载excel(.xls)文件?

时间:2021-02-06 01:45:38

I am having an API-Endpoint and Authtoken for that API

我正在为该API提供API-Endpoint和Authtoken

the said API is for .XLS report download, how can i view the downloaded .xls file using (if possible) POSTMAN?

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

If it is not possible using postman what are the other programmatic ways I should be looking for?

如果使用邮递员是不可能的,那么我应该寻找的其他程序化方法是什么?

3 个解决方案

#1


192  

Try selecting "send and download" instead of "send" when you make the request. (the blue button)

提出请求时,请尝试选择“发送和下载”而不是“发送”。 (蓝色按钮)

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

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

"For binary response types, you should select “Send and download” which will let you save the response to your hard disk. You can then view it using the appropriate viewer."

“对于二进制响应类型,您应该选择”发送和下载“,这样您就可以将响应保存到硬盘中。然后您可以使用适当的查看器查看它。”

#2


3  

If the endpoint really is a direct link to the .xls file, you can try the following code to handle downloading:

如果端点确实是.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;
}

All you should need to do is set the proper name for the auth token and fill it in.

您需要做的就是为auth令牌设置正确的名称并填写。

Example usage:

用法示例:

download(new File("C:\\output.xls"), "http://www.website.com/endpoint");

#3


0  

In postman - Have you tried adding the header element 'Accept' as 'application/vnd.ms-excel'

邮递员 - 您是否尝试将标题元素'Accept'添加为'application / vnd.ms-excel'

#1


192  

Try selecting "send and download" instead of "send" when you make the request. (the blue button)

提出请求时,请尝试选择“发送和下载”而不是“发送”。 (蓝色按钮)

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

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

"For binary response types, you should select “Send and download” which will let you save the response to your hard disk. You can then view it using the appropriate viewer."

“对于二进制响应类型,您应该选择”发送和下载“,这样您就可以将响应保存到硬盘中。然后您可以使用适当的查看器查看它。”

#2


3  

If the endpoint really is a direct link to the .xls file, you can try the following code to handle downloading:

如果端点确实是.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;
}

All you should need to do is set the proper name for the auth token and fill it in.

您需要做的就是为auth令牌设置正确的名称并填写。

Example usage:

用法示例:

download(new File("C:\\output.xls"), "http://www.website.com/endpoint");

#3


0  

In postman - Have you tried adding the header element 'Accept' as 'application/vnd.ms-excel'

邮递员 - 您是否尝试将标题元素'Accept'添加为'application / vnd.ms-excel'