我正在使用 Apache httpclient 和多部分请求将图像文件上传到服务器。 我能够通过其他客户端(如 iphone 和 fiddler)成功上传文件,以在服务器端调用相同的 api 调用。 Android 没那么幸运...
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(appController.getInstance().getURL().concat("/Api/ApiSales/UploadImages"));
post.addHeader("Authorization", appController.getInstance().getAuthTokenString());
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE)
File fileDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), Global.PHOTO_DIR);
for (File file : fileDir.listFiles()){
if (file.getName().equals("campusMarketLogo.png")){
Log.i("", "found campus logo file!");
FileInputStream fin = null;
try {
fin = new FileInputStream(file);
} catch (FileNotFoundException e) {
Log.e("", e.getLocalizedMessage());
}
byte[] fileContent = new byte[(int)file.length()];
try {
fin.read(fileContent);
} catch (IOException e) {
Log.e("", e.getLocalizedMessage());
}
ByteArrayBody bab = new ByteArrayBody(fileContent,"image/png",file.getName());
entity.addPart("File", bab);
}
}
post.setEntity(entity);
try {
client.execute(post, new uploadResponseHandler());
} catch (IOException e) {
Log.e("something is wrong", e.getLocalizedMessage());
}
当我从 Wireshark 读取我的日志时,我看到一些 TCP 错误:
[TCP Retransmission] 62941→80 [ACK] Seq=676 Ack=1 Win=14656 Len=1448 TSval=161633 TSecr=516688742[Reassembly error, protocol TCP: New fragment overlaps old data (retransmission?)]
为什么会出现这样的TCP错误?
最佳答案
这是 TCP 完全可以接受的行为。丢失的返回 ACK
将导致重新传输实际收到的数据,可能比原始数据更大,并且还包括后来的数据。接收方将静默丢弃已接收到的数据的额外副本。
关于java - android Apache httpclient 上传文件,.出现一些奇怪的 TCP 重组错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27698253/