2017-10-31 5 views
0

가있는 JSON 응답을 검색하는 방법, 우리는 Send and Download을 할 수 있습니다 결과 zip 파일 저장</p> <pre><code>content-disposition →attachment;filename="results.zip" content-type →text/plain; charset=UTF-8 </code></pre> <p>이죠에 응답의 헤더를 여기 저기 GET API를 REST 호출 요청이 실행이 zip 파일을 제공에 있으며 첨부 파일

나는 RestAssured을 사용하여 REST API 호출을 테스트합니다.

API 호출에서 결과 zip 파일을 검색하는 방법을 누군가 도울 수 있습니까?

답변

0

업데이트 : 우리는 응답을 InputStream 또는 Byte Array로 가져올 수 있고 나머지를 ZipFile에 쓸 수있는 솔루션을 찾았습니다. 의 InputStream으로

: -이 ByteArray로

// Get the response as Input Stream 
    InputStream is = result.getBody().asInputStream(); 
    OutputStream stream = new FileOutputStream("D:\\Test.zip"); 
    int read = 0; 
    byte[] bytes = new byte[1024]; 

    while ((read = is.read(bytes)) != -1) { 
     stream.write(bytes, 0, read); 
    } 
    System.out.println("Zip file captured successfully"); 

: -

//이 ByteArray

byte[] arraybyteResponse = result.getBody().asByteArray(); 
    ByteBuffer buffer = ByteBuffer.wrap(arraybyteResponse); 
    OutputStream os = new FileOutputStream("D:\\Test.zip"); 
    WritableByteChannel channel = Channels.newChannel(os); 
    channel.write(buffer); 
    System.out.println("Zip file captured successfully"); 
같은 응답을 받기