0
我的应用程序分发文件和收集统计信息。 前段时间我注意到如果用户尝试从android下载文件 - 服务器收到两个请求,而不是一个。第一次请求失败,原因是Caused by: java.net.SocketException: Connection reset by peer: socket write error
第二次请求处理正确,用户在手机上收到文件。所以它或多或少都可以,但在这种情况下,我的统计数据不正确。我看到similiar问题上[其他线程] [1]Android浏览器问题。下载使两个请求,而不是一个
[1]:https://stackoverflow.com/a/8579181/273418但目前还没有任何解决方案
的servlet代码分发文件
try {
StringBuilder typeHeader = new StringBuilder("application/vnd.android.package-archive");
String contentType = FdConstants.CONTENT_TYPE_HEADER.getValue();
response.setHeader(contentType, typeHeader.toString());
StringBuilder dispositionHeader = new StringBuilder("attachment; filename=\"");
dispositionHeader.append(fileName.toUpperCase());
dispositionHeader.append("\"");
String contentDisposition = FdConstants.CONTENT_DISPOSITION_HEADER.getValue();
response.setHeader(contentDisposition, dispositionHeader.toString());
response.setContentLength(fileStream.available());
// copy it to response's OutputStream
IOUtils.copy(fileStream, response.getOutputStream());
response.flushBuffer();
} finally {
IOUtils.closeQuietly(fileStream);
}
如何下载文件?请添加一些代码。 – RvdK 2013-03-05 14:32:54
通过网址浏览器 – Diyko 2013-03-05 14:59:15
你为什么然后谈论'你的''应用程序?您是否使用WebView,Android上的不同浏览器(海豚/铬),电视上的浏览器在自定义应用程序中尝试过它? – RvdK 2013-03-05 15:20:35