springboot+vue+elementUI项目中,写一个从路径10.0.90.52/oath下载PDF文件的API
时间: 2023-06-06 17:08:14 浏览: 104
可以使用Java中的HttpClient类来实现从指定路径下载PDF文件的API。以下是示例代码:
```java
@RequestMapping("/download")
public ResponseEntity<byte[]> downloadPDF() throws IOException {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet("http://10.0.90.52/oath");
CloseableHttpResponse response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
byte[] bytes = EntityUtils.toByteArray(entity);
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Disposition", "attachment;filename=" + "file.pdf");
HttpStatus status = HttpStatus.OK;
ResponseEntity<byte[]> responseEntity = new ResponseEntity<>(bytes, headers, status);
return responseEntity;
}
```
这个API将会提供一个/download的接口,当调用该接口时,会返回一个名为file.pdf的PDF文件。
阅读全文