Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.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
Http 下载作为字节响应返回的PDF_Http - Fatal编程技术网

Http 下载作为字节响应返回的PDF

Http 下载作为字节响应返回的PDF,http,Http,我正试图从另一个函数的调用中获得一个下载打开,该函数将其作为响应字节返回。问题是当它返回时,它没有在浏览器中下载。当我查询直接调用的函数时,将打开一个下载框 byte[] content = ...//gets the content HttpHeaders header = new HttpHeaders(); header.setContentType(MediaType.parseMediaType("application/pdf")); return new ResponseEnti

我正试图从另一个函数的调用中获得一个下载打开,该函数将其作为响应字节返回。问题是当它返回时,它没有在浏览器中下载。当我查询直接调用的函数时,将打开一个下载框

byte[] content = ...//gets the content
HttpHeaders header = new HttpHeaders();
header.setContentType(MediaType.parseMediaType("application/pdf"));

return new ResponseEntity<byte[]>(contents, header, HttpStatus.OK);
byte[]content=…//获取内容
HttpHeaders header=新的HttpHeaders();
header.setContentType(MediaType.parseMediaType(“application/pdf”);
返回新的响应属性(内容、标题、HttpStatus.OK);

当我从javascript调用它时,为什么浏览器中没有出现下载框?我遗漏了什么吗?

请在响应中包含以下标题,指示浏览器下载文件

Response.AddHeader("content-disposition", "attachment;filename=<yourfilename>.pdf");
Response.AddHeader(“内容处置”、“附件;文件名=.pdf”);

将上述代码中的中的朋友文件名替换为默认文件名。

这对我不起作用。我试过:header.add(“内容处置”,“附件;文件名=test.pdf”);我也尝试过:header.setContentDispositionFormData(“file.pdf”、“file.pdf”);