Apache HttpClient UrlEncodedFormEntity 限制大小
我正在使用 Apache HttpClient 与 WS 连接。一切正常,但是当应用程序尝试发送大尺寸的帖子时,它就崩溃了。
我像这样取消 HttpClint:
- Doing a post of an XML to a REST WS
- 这个帖子是一个字符串,该字符串是映射为 XML 的对象。
- 我使用 UrlEncodedFormEntity 将 xml 参数传递给 url
当 HttpClient 发送内容时,从 WS 端,带有 XML 的参数为空。 我检查了 xml 发送的时间,一切正常,我的意思是 XML 已正确创建。
如果 xml 的大小较小,则效果很好。 它的行为就像 HttpClient 有 post 大小限制或 UrlEncodedFormEntity 有限制一样。
有什么想法吗? 谢谢。
I'm using Apache HttpClient to connect with a WS. All works fine but when the application try to send a post with a big size it brokes.
I'm unsing HttpClint like this:
- Doing a post of an XML to a REST WS
- This post is an String, the string is an object mapped as XML.
- I'm using UrlEncodedFormEntity to pass the xml parameter to the url
When the HttpClient send the contetn, from the WS side, the parameter with the XML is empty.
I cheked the when the xml is sent and is ok, I mean the XML is correctly created.
If the size of the xml is smaller, then it works fine.
It's behavor is like if HttpClient has a limit size for post or the UrlEncodedFormEntity does.
any idea?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您要发布 XML 文件,则不应使用 UrlEncodedFormEntity,而应将 FileEntity 与 XML 文件一起使用。这样您就可以避免 UrlEncodedFormEntity 限制。
If you are posting an XML file, you should not use UrlEncodedFormEntity, you should use FileEntity with the XML file. This way you can avoid the UrlEncodedFormEntity limit.
UrlEncodedFormEntity
不会对内容长度施加任何限制,但许多 HTTP 服务器实际上会这样做,因为“application/x-www-form-urlencoded”内容通常会缓冲在内存中在服务器端。UrlEncodedFormEntity
does not impose any limit on the content length, but many HTTP servers actually do, as 'application/x-www-form-urlencoded' content usually gets buffered in memory on the server side.感谢您的帮助,解决方案很简单:限制在 Tomcat 中,因为默认情况下 maxPostSize 参数为 2MB(我的意思是如果它不存在于 server.xml 中的连接器标记中),所以我将其更改为 15Mb。我找到了带有 HTTP 协议的标签连接器,并为 !5Mb 添加了属性 maxPortSize="15728640",它工作正常!!!!
Thanks for the help, the solution was easy: The limitation was in the Tomcat becouse by default the maxPostSize parameter is 2MB (I mean if it is not present at the connector tag in server.xml), so I changed it to 15Mb. I locate the tag connector with protocol HTTP and added the attribute maxPortSize="15728640" for !5Mb and it works ok!!!!