如何从邮递员的API下载excel(.xls)文件?

我有一个API端点和Authtoken该API

该API是.XLS报告下载,我怎样才能查看下载的.xls文件使用(如果可能)POSTMAN?

如果使用邮递员是不可能的,那么我应该寻找哪些其他编程方式?

请求时请尝试select“发送和下载”而不是“发送”。 (蓝色button)

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

“对于二进制响应types,您应该select”发送和下载“,这样可以将响应保存到硬盘上,然后使用相应的查看器进行查看。

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

所有你需要做的就是为auth令牌设置合适的名字并填写它。

用法示例:

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

在邮递员 – 你有没有尝试添加头元素'接受'作为'application / vnd.ms-excel'

Interesting Posts