HttpPost文件上传数据丢失

发布于 2024-10-23 17:52:41 字数 1348 浏览 1 评论 0原文

从我的应用程序中,我使用这个基本代码将文件上传到我们的服务器(当然比这多一点,但基本上就是这样)

HttpParams params = new BasicHttpParams(); 
HttpConnectionParams.setConnectionTimeout(params, 15000); 
HttpConnectionParams.setSoTimeout(params, 5 * 60 * 1000); 
HttpClient client = new DefaultHttpClient(params); 
HttpPost  post = new HttpPost("upload url"); 
HttpEntity requestEntity = (new FileEntity(tmpFile, "multipart/form-data;boundary="+boundary); 
post.setEntity(requestEntity); 
HttpResponse response = (HttpResponse) client.execute(post); 

,大多数情况下工作正常。

对于某些运行 Android 2.2+ 的手机,服务器接收到的文件 侧面不完整。文件的一小部分丢失了, 并且丢失的部分位于文件的不同位置 每次。

我们通过将应用程序中的文件与其他文件进行比较来验证这一点 是在服务器端接收到的。在服务器端我们捕获了 使用 tcpdump 打包数据包以确保这不是我们网络的问题 服务器或网络服务器代码。

我们还通过手机上的 tcpdump 检查了数据。手机中的 tcpdump 文件与我们尝试发送的数据确实不同。对于一种情况,我们对 tcpdump 文件进行了分析,文件中缺少地址 8d68 和 9000 之间的数据。来自 tcpdump 的数据包与这些地址对齐(一个数据包包含直到 8d68 的部分数据,然后下一个数据包包含从 9000 开始的数据)。

对于这些手机,问题只是偶尔发生。有时 文件上传工作正常,整个文件在我们这边完好无损地收到。

这种情况仅发生在 2.2+ 手机上。它发生在各种各样的情况下 电话和各种运营商以及数百个用户。根据服务器端看到的 IP 地址,这似乎是通过 wifi 和 3g 发生的。

这是轶事,但在过去 2 天里,当我试图在我的 Nexus 上实现这种情况时,我已经看到这种情况发生了 6 次,而且这些次数总是在我进入或离开靠近某个 wifi 路由器的房间时发生。当天剩下的时间里,当我在办公室使用不同的 wifi 路由器或手机网络时,这个问题永远不会发生。我的理论是应用程序正忙于发送数据,现在我们从 WiFi 转移到蜂窝网络,反之亦然,这是一个愚蠢的想法还是一种可能性?

如果有人愿意看的话,我可以将 tcpdump 文件和数据文件放在某个地方。

我还应该调查什么来找出原因?

From my app I upload a file to our server using this basic code (it is a bit more than this of course but this is basically it)

HttpParams params = new BasicHttpParams(); 
HttpConnectionParams.setConnectionTimeout(params, 15000); 
HttpConnectionParams.setSoTimeout(params, 5 * 60 * 1000); 
HttpClient client = new DefaultHttpClient(params); 
HttpPost  post = new HttpPost("upload url"); 
HttpEntity requestEntity = (new FileEntity(tmpFile, "multipart/form-data;boundary="+boundary); 
post.setEntity(requestEntity); 
HttpResponse response = (HttpResponse) client.execute(post); 

That works fine MOST of the time.

For some phones running Android 2.2+ the file received on the server
side is not complete. Small portions of the file are simply missing,
and the parts that are missing are at different locations of the file
each time.

We have verified this by comparing the file from the app against what
is received on the server side. On the server side we captured
packets with tcpdump to make sure it wasn't an issue with our web
server or web server code.

We also checked the data with tcpdump from the phone. The tcpdump file from the phone DOES differ from the data we are trying to send. For one case we did analysis on the tcpdump file is missing data between the address 8d68 and 9000 from the file. The packets from tcpdump line up with those addresses (one packet has a portion of the data up until 8d68 and then the next packet has data starting from 9000).

For these phones the problem only happens some of the time. Sometimes
file uploads work and the entire file is received intact on our end.

This is happening ONLY for 2.2+ phones. It happens for a wide variety
of phones, and a variety of carriers, and for hundreds of users. It appears to happen over both wifi and 3g based on the IP addresses seen on the server side.

This is anecdotal but when trying to get this to happen on my Nexus over the past 2 days I have seen it happen 6 times and those times are always right around when I am entering or leaving the room close to a certain wifi router. The rest of the day when I'm in the office on a different wifi router or on a cell network the issue never happens. My theory being that the app is busy sending data and now we move from wifi to cell network or vice versa, is that a dumb idea or a possibility?

I can put the tcpdump files and data files up somewhere if anyone cares to take a look.

What else should I be investigating to figure out the reason for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱格式化 2024-10-30 17:52:41

我在上传二进制数据时遇到了一些类似的问题。我发现这是服务器代码的问题。
服务器端有一些过滤器,它们正在读取传入的请求并尝试记录它们。该代码试图将传入流放入 DS 的某种字符串类型中。正因为如此,二值图像才被扭曲。
只需检查服务器端是否有过滤器即可。希望这有帮助

I was facing some similar issue when uploading the binary data. I figured out that it was a problem with the server code.
There were some filters at the server side, which were reading the incoming requests and trying to log them. The code was trying to put the incoming stream in some String type of DS. Its was because of this that the binary images were distorted.
Just check if there are any filters at the server side. Hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文