Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring webclient消费应用程序/pdf_Spring_Pdf_Spring Webflux - Fatal编程技术网

Spring webclient消费应用程序/pdf

Spring webclient消费应用程序/pdf,spring,pdf,spring-webflux,Spring,Pdf,Spring Webflux,我一直在尝试使用一个输出为PDF文件的REST端点。源端点正确返回PDF,但当我使用SpringWebLClient像下面这样使用并转换为文件时,打开时会出现错误“文件已损坏” 也尝试了字节数组资源(),但我怀疑字节转换可能会导致文件损坏,因此使用了InputStream,但存在相同的问题,是否有指针 示例代码 InputStream mono = WebClient.create().get().uri(UriComponentsBuilder.fromUriString(serviceUr

我一直在尝试使用一个输出为PDF文件的REST端点。源端点正确返回PDF,但当我使用SpringWebLClient像下面这样使用并转换为文件时,打开时会出现错误“文件已损坏”

也尝试了字节数组资源(),但我怀疑字节转换可能会导致文件损坏,因此使用了InputStream,但存在相同的问题,是否有指针

示例代码

 InputStream mono = WebClient.create().get().uri(UriComponentsBuilder.fromUriString(serviceUri)).build().toUri())
        .accept(MediaType.APPLICATION_PDF)
        .exchange()
        .flatMap(response -> response.bodyToMono(InputStreamResource.class))
        .map(inputStreamResource -> {
          try {
            return inputStreamResource.getInputStream();
          } catch (IOException e) {
            e.printStackTrace();
          }
          return null;
        }).block();


try(OutputStream outputStream = new FileOutputStream("c:\\report.pdf")) {
  try {
    IOUtils.copy(mono, outputStream);
  } catch (IOException e) {
    e.printStackTrace();
  }
} catch (FileNotFoundException e | IOException e) {
  e.printStackTrace();
} 

您是否尝试过bufferedoutputstream并最终刷新它,并使用exception添加了一个捕获以获取任何异常类型最终发现问题,我们没有传递正确的身份验证头,因此响应流没有任何内容!