使用HTTPClient或HttpUrlConnection? [英] Use HTTPClient or HttpUrlConnection?

查看:167
本文介绍了使用HTTPClient或HttpUrlConnection?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在JRE 1.4上实现REST客户端。

We're implementing a REST client on JRE 1.4.

似乎客户端REST框架的两个好选择是 HttpClient HttpUrlConnection

Seems two good options for a client REST framework are HttpClient and HttpUrlConnection.

是否有理由在JRE的HttpUrlConnection上使用HttpClient?

Is there a reason to use HttpClient over the JRE's HttpUrlConnection?

推荐答案

<我会给你一个明确的理由来支持Apache的HTTPClient而不是JDK实现:JDK的 HttpUrlConnection 不支持超时*,Apache的HTTPClient支持。

I'll give you a single, concrete reason to favour Apache's HTTPClient over the JDK implementation: The JDK's HttpUrlConnection doesn't support timeouts*, Apache's HTTPClient does.

应用程序应始终能够在调用其他系统(数据库,远程服务,您自己的服务器后端......)时设置超时。

Applications should always have the ability to set timeouts when calling into other systems (databases, remote services, your own server backend, ...).

*这已在Java 1.5中修复; Java 1.5及更高版本支持HttpUrlConnection中的超时。

这篇关于使用HTTPClient或HttpUrlConnection?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆