web-dev-qa-db-ja.com

郵便配達人にAPIからExcel(.xls)ファイルをダウンロードするには?

私はそのAPIのためのAPIエンドポイントと認証を持っています

上記のAPIは.XLSレポートのダウンロード用ですが、(可能であれば)POSTMANを使用してダウンロードした.xlsファイルを表示する方法を教えてください。

それがpostmanを使用して不可能である場合、私が探しているべきである他のプログラムの方法は何ですか?

130
praxnet

リクエストを送信するときに、「送信」ではなく「送信とダウンロード」を選択してみてください。 (青いボタン)

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

「バイナリレスポンスタイプの場合は、「Send and download」を選択して、ハードディスクにレスポンスを保存するようにします。その後、適切なビューアを使用してそれを表示できます。」

271
Jake

エンドポイントが実際に.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");
4
nbokmans

あなたは郵便配達員のこの画像をチェックして応答の右側にあるオプションで応答(pdf、docなど)を保存するだけです postman save response

詳細はこちらをご覧ください

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

1
Akitha_MJ

郵便配達員 - 'application/vnd.ms-Excel'として 'Accept'というヘッダ要素を追加してみましたか

0
jikku