【问题标题】:Android browser issue. Download makes two requests instead one安卓浏览器问题。下载提出两个请求而不是一个
【发布时间】:2013-02-20 00:07:19
【问题描述】:

我的应用分发文件并收集统计信息。 前段时间我注意到如果用户尝试从 android 下载文件 - 服务器收到两个请求而不是一个。由于Caused by: java.net.SocketException: Connection reset by peer: socket write error,第一个请求失败 第二个请求已正确处理,用户在手机上收到了文件。所以或多或少都可以,但在这种情况下,我的统计数据不正确。我在 [the other thread][1] 上看到了类似的问题

[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);
}

【问题讨论】:

  • 如何下载文件?请添加一些代码。
  • 你为什么要谈论“你的”应用程序?您是否在带有 WebView、Android 上的不同浏览器(dolphin/chrome)、电视上的浏览器的自定义应用程序中尝试过?
  • 我的意思是我的网络应用,问题出现在默认的安卓浏览器上

标签: java android download request


【解决方案1】:
猜你喜欢
  • 2010-12-19
  • 2015-04-15
  • 2022-11-12
  • 1970-01-01
  • 2013-09-15
  • 2012-01-18
  • 2023-03-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多