java访问后台接口,下载文件

添加响应头:

response.addHeader("Content-Disposition", "attachment; filename=" + response.encodeURL(downloadfile));

   private void genCode(HttpServletResponse response, byte[] data) throws IOException
    {
        response.reset();
        response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\"");
        response.addHeader("Content-Length", "" + data.length);
        response.setContentType("application/octet-stream; charset=UTF-8");
        IOUtils.write(data, response.getOutputStream());
    }

 

posted @ 2021-04-28 10:55  o_osky  阅读(1169)  评论(0编辑  收藏  举报