java - android Apache httpclient 上传文件,.出现一些奇怪的 TCP 重组错误

标签 java android apache tcp

我正在使用 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/

相关文章:

android - 在 Android 中安装 PEM 证书的正确方法

php - 当访问在代理中使用 apache 和 nginx 托管的 wordpress 时重定向到 127.0.0.1

java - 将 JSON 响应存储在数组中

java - Fragment和FragmentList Android Studio "Unable to start activity ComponentInfo"

java - Tomcat 缓存单点登录系统的旧 dns 条目

java - 如何将android开关小部件旋转90°

javascript - index.html 的 mod_rewrite 打破了深度 URL 的相对路径

php - 使用 Ubuntu mate 的 Apache 和 Mysql

java - 如何使用 HTML 标签为 strings.xml 文件中的字符串着色?

java - Criteria API 不在 @ElementCollection 中