使用远程流下载pdf文件,更新到正式环境后下载的文件大小为0,查看日志发现是输入流有问题,但没有报错

qq_42543962 2019-01-23 04:26:33
URL url = new URL(filePath);
conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(3 * 1000);

conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
conn.setRequestProperty("Charset", "UTF-8");
conn.setReadTimeout(8 * 1000);
conn.connect();
System.out.println("***************************11111111"+conn+"****************************************************");

response.setCharacterEncoding("utf-8");
response.setContentType(WebUtility.getHttpContentType(filePath.substring(filePath.lastIndexOf("."))));
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
// response.setHeader("Content-Disposition", "attachment;fileName="+new String(fileName.getBytes("GBK"),"iso8859-1"));
response.setHeader("Content-Disposition", "attachment;fileName="+strNewFileName+filePath.substring(filePath.lastIndexOf(".")));
response.setHeader("Cache-Control", "max-age=0");
inputStream = conn.getInputStream() ;
System.out.println("***************************22222"+inputStream+"****************************************************");

outputStream = response.getOutputStream();
byte[] b = new byte[1024];
int length;
while ((length = inputStream.read(b)) > 0) {
outputStream.write(b, 0, length);
}
System.out.println("***************************over"+outputStream+"****************************************************");



查看服务器端日志只有11111111,后面的2222和over都没有输出
...全文
95 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

67,514

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧