[Android]HttpClient post/put StringEntity 长度限制?

发布于 2024-11-03 10:46:29 字数 456 浏览 1 评论 0原文

我发现 HttpClient 发布/放置长 StringEntity 时出现问题。当实体很短时,完全没有问题。但是,当长度超过某个值(大约1400个字符)时,http数据包将永远无法发送出去(我使用WireShark嗅探了接口)。实际上,连接建立了,但是数据没有传输,所以接收方出现了超时异常。 我想知道这些是否有长度限制。 我尝试增加连接超时和套接字超时,这只会让我等待更长时间才能看到超时...... 我也尝试使用InputStreamEntity,但也不起作用。

[更新]:我尝试直接使用 HttpURLConnection 而不是 HttpClient。同样的问题仍然存在。不过,我确实有一些发现。当我强制将数据包切成块(使用 HttpURLConnection.setChunkedStreamingMode)时,WireShare 确实捕获了数据包的某些片段,但前面的片段丢失了。我想这一定是 apache http 库中的一个错误。

I'm seeing a problem with the HttpClient posting/putting a long StringEntity. When the entity is short, there is no problem at all. However, when the length exceeds a value (something around 1400 characters), the http packet can never be sent out (I sniffed the interface using WireShark). Actually, the connection is established, but the data is not transmitted, so the receiver side got a timeout exception.
I'm wondering if these is a lenght limit.
I tried to increase the connection timeout and socket timeout, which only made me wait longer to see the timeout ...
And i also tried to use InputStreamEntity, didn't work either.

[Update]: I tried to used HttpURLConnection directly instead of HttpClient. The same problem still exists. However, I do have some findings. When I forced the packet to be cut into chunks (using HttpURLConnection.setChunkedStreamingMode), WireShare did captured some segment of the packet, with the previous segments missing. I guess this must be a bug in the apache http library.

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

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

发布评论

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

评论(3

入画浅相思 2024-11-10 10:46:29

问题已解决。我花了几天时间才发现问题出在我的无线路由器上。它有一些奇怪的设置,会截断大量传入的 http 消息。

The issue is resolved. It took me several days to find out that, the problem is with my wireless router. It has some weird settings which truncates large incoming http messages.

一紙繁鸢 2024-11-10 10:46:29

服务器端可能超时。还要确保您使用的是 org.apache.client.httpclient jar。官方没有规定 URL 的最大长度。看这里 http://www.w3.org/Protocols/rfc2616/rfc2616.html

It is possible it is timing out on the server side. Also make sure you are using the org.apache.client.httpclient jar. Officially there is no max length for a url. Look here http://www.w3.org/Protocols/rfc2616/rfc2616.html

不即不离 2024-11-10 10:46:29

我认为这可以帮助你urllength

I think that can help you urllength

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