0

My app distributes files and collects statistics. Some time ago I noticed if user try download file from android - server received two requests instead one. First request failed due to Caused by: java.net.SocketException: Connection reset by peer: socket write error Second request was processed correctly and user received file on phone. So it's more or less ok but in such case my statistics are incorrect. I saw similiar issue on [the other thread][1]

[1]: https://stackoverflow.com/a/8579181/273418 but there is no any solution

Code of servlet that distributes files

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);
}
Community
  • 1
  • 1
Diyko
  • 388
  • 1
  • 8
  • 28
  • How do you download the file? Please add some code. – RvdK Mar 05 '13 at 14:32
  • Why are you then talking about 'your' app? Have you tried it in a custom app with WebView, different browser on Android (dolphin/chrome), browser on TV? – RvdK Mar 05 '13 at 15:20
  • i meant my web app, issue appears on default android browser – Diyko Mar 05 '13 at 19:33

1 Answers1

0

As designed behavior https://code.google.com/p/android/issues/detail?id=1978 Similiar issue here Android is sending 2 requests to download one file via mobile browser

Community
  • 1
  • 1
Diyko
  • 388
  • 1
  • 8
  • 28