Chrome会产生两个请求

问题描述 投票:0回答:1

在春季启动应用程序的链接生成一个PDF文件。

链接不thymeleaf

<a th:href="@{/printings/bytesttype/compressions}" class="list-group-item list-group-item-action"><span th:text="#{compressions}">Compressions</span></a>

在控制器端

@GetMapping(value = "/printings/bytesttype/compressions")
    public ResponseEntity<byte[]> getCompressionsReport() throws IOException, Exception {
        return preparePdfReport(samplingFacade.getCompressionToPrint());
    }

private ResponseEntity<byte[]> preparePdfReport(byte[] content) throws IOException {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.parseMediaType("application/pdf"));
        String fileName = "report.pdf";
        headers.setContentDispositionFormData(fileName, fileName);
        headers.setCacheControl("no-cache, must-revalidate, post-check=0, pre-check=0");
        ResponseEntity<byte[]> response = new ResponseEntity<>(content, headers, HttpStatus.OK);
        return response;
    }

其实用户点击,请求完成。

之后另一个请求完成与扩展开

镀铬的扩展:// oemmndcbldboiebfnladdacbdfmadadm / http://localhost:8080/printings/bytesttype/compressions

有没有办法避免?

试图Chrome sends two requests when downloading a PDF (and cancels one of them)

问题仍然存在

spring google-chrome chromium
1个回答
0
投票

如果你没有表现出与扩展(浏览器内嵌),PDF你可以尝试添加头部的HTTP响应如下:

response.setHeader("Content-Disposition", "attachment; filename=report.pdf");
© www.soinside.com 2019 - 2024. All rights reserved.