我应该在 Java 应用程序中使用 java.net 或 org.apache.http 库来实现 HTTP 吗?
关于这两个 HTTP 库之间的权衡,我应该了解哪些信息?
What should I know about the trade-offs between these two HTTP libraries?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,apache 库易于使用且可靠,但正如 aioobe 所说,引入了外部依赖项(鉴于具有 apache 许可证,这对于商业产品来说不应该成为问题)。恕我直言,如果您必须处理大量同时连接,我会选择 apache lib,因为性能可能会更好。
查看这篇文章:http://lassewesth .blogspot.com.es/2009/05/i-like-apache-http-client-over.html
Well, the apache library is easy to use and reliable, but as aioobe said introduces external dependencies (given that has apache license that should not be a problem for commercial products). IMHO if you have to handle a lot of simultaneous connections I will go for the apache lib as the performance will be probably better.
Check this article: http://lassewesth.blogspot.com.es/2009/05/i-like-apache-http-client-over.html
我会说取决于你的需求。我在执行简单的 GET 和 POST 时使用了 java.net。突然我需要对会话cookie等的支持,所以我切换到了HTTPClient。
这也是我的一般建议。不要为无需第三方库即可轻松完成的简单任务引入对第三方库的依赖。
Depends on your needs I would say. I used the java.net one while doing simple GETs and POSTs. Suddenly I needed support for session cookies etc, and I switched to the HTTPClient.
That's also my general recommendation. Don't introduces dependencies on third-party libraries for simple tasks that can be easily done without.