IT박스

Postman의 API에서 Excel (.xls) 파일을 다운로드하는 방법은 무엇입니까?

itboxs 2020. 6. 16. 20:40
반응형

Postman의 API에서 Excel (.xls) 파일을 다운로드하는 방법은 무엇입니까?


해당 API에 대한 API-Endpoint 및 Authtoken이 있습니다.

상기 API는 .XLS 보고서 다운로드 용이며 POSTMAN을 사용하여 다운로드 한 .xls 파일을 어떻게 볼 수 있습니까?

우편 배달원을 사용할 수 없다면 다른 프로그래밍 방법은 무엇입니까?


요청시 "보내기"대신 "보내기 및 다운로드"를 선택하십시오. (파란색 버튼)

https://www.getpostman.com/docs/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");

당신은 우편 배달부의 응답 오른쪽에 옵션으로 응답 (pdf, 문서 등)을 저장할 수 있습니다.이 이미지를 확인하십시오 우편 배달부 응답 저장

자세한 내용은 이것을 확인하십시오

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


우편 배달부-헤더 요소 'Accept'를 'application / vnd.ms-excel'으로 추가 해 보셨습니까?

참고 URL : https://stackoverflow.com/questions/38975718/how-to-download-excel-xls-file-from-api-in-postman

반응형