【问题标题】:android Apache httpclient upload file,. got some weird TCP reassembly errorandroid Apache httpclient 上传文件,。有一些奇怪的 TCP 重组错误
【发布时间】:2015-02-26 04:38:18
【问题描述】:

我正在使用 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重传] 62941→80 [ACK] Seq=676 Ack=1 Win=14656 Len=1448 TSval=161633 TSecr=516688742[重组错误,TCP协议:新片段与旧数据重叠(重传?)]

为什么会出现这样的 TCP 错误?

【问题讨论】:

    标签: java android apache tcp


    【解决方案1】:

    这是一个完全可以接受的 TCP 行为。丢失的返回ACK 将导致重新传输实际接收到的数据,可能大于原始数据并且还包括后来的数据。接收者会默默地丢弃它已经接收到的额外数据副本。

    【讨论】:

      猜你喜欢
      • 2013-12-14
      • 2023-03-22
      • 2011-09-22
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 2012-01-22
      • 1970-01-01
      相关资源
      最近更新 更多