English 中文(简体)
Use HTTPClient or HttpUrlConnection? [closed]
原标题:
Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 7 years ago.

We re implementing a REST client on JRE 1.4.

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

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

问题回答

I would recommend Jakarta Commons HTTP Client over java.net.HttpUrlConnection as it is more mature and has a richer feature set. For example you can ask it to set up multi-threaded connection pool (see MultiThreadedHttpConnectionManager), and it has full support for all the HTTP methods (GET, PUT, POST, DELETE, OPTIONS, TRACE).

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, ...).

* This was fixed in Java 1.5; Java 1.5 and higher support timeouts in HttpUrlConnection.

The Restlet Framework also has an API which works both server-side and client-side. We support pluggable client connectors, leveraging HttpURLConnection or Apache HTTP Client or our own internal HTTP client.

Our ClientResource class provides a higher level HTTP client API, with features like automatic redirection, transparent conversion between objects and representations, content negotiation and more.

Best regards,

Jerome Louvel

Restlet ~ Founder and Lead developer ~ http://www.restlet.org

Noelios Technologies ~ Co-founder ~ http://www.noelios.com

In my experience HttpClient is slightly easier and more intuitive to use than using HttpUrlConnection, but I think it s a very subjective decision and YMMV.

I d go with the JRE version just so I would have one less dependency to ship around.

... httpclient does not support kerberos/ntlm authentication for proxies etc... java s httpurlconnection will do authentication out of the box...

The HttpUrlConnection is easy to handle. REST implementations are quite simple.

Although you must consider the whole environment about this implementation and check what will work better for you.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签