Alternatives to Apache HttpComponents? [closed]

Solution 1:

Complexity of HttpClient API simply reflects the complexity of its problem domain. Contrary to a popular misconception HTTP is a fairly complex protocol. Being a low level transport library HC 4.0 API was primarily optimized for performance and flexibility rather than simplicity. It is regrettable that you are not able to figure it out, but so be it. You are welcome to use whatever library that suits your needs best. I personally like Jetty HttpClient a lot. It is a great alternative that might work better for you.

Solution 2:

For simple use cases you can use HttpClient Fluent API. See tutorials.

This module provides an easy to use facade API for HttpClient based on the concept of a fluent interface. Fluent facade API exposes only the most fundamental functions of HttpClient and is indended for simple use cases that do not require the full flexibility of HttpClient. For instance, fluent facade API relieves the users from having to deal with connection management and resource deallocation

    // Execute a GET with timeout settings and return response content as String.
 Request.Get("http://somehost/")
        .connectTimeout(1000)
        .socketTimeout(1000)
        .execute().returnContent().asString();

Maven artifact.

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>fluent-hc</artifactId>
    <version>4.2.5</version>
</dependency>

Solution 3:

Answering my own question since this got resurrected for some reason.

I ended up writing a few simple wrappers around java.net.HttpURLConnection, seems it's come a long way since the last time I seriously considered it.

Apache HttpComponents is great, but can be overkill for simple tasks. Also, at least in my scenario, HUC is noticeably faster (mostly single-threaded, haven't done any testing under heavy load).

Solution 4:

jsoup

jsoup is a library designed to parse HTML files. It does make HTTP calls to retrieve the source code of a web page.

Document doc = Jsoup.connect("http://en.wikipedia.org/").get();

Solution 5:

Google HTTP Client

Another library is Google HTTP Client Library for Java.

Written by Google, this library is a flexible, efficient, and powerful Java client library for accessing any resource on the web via HTTP. It features a pluggable HTTP transport abstraction that allows any low-level library to be used, such as java.net.HttpURLConnection, Apache HTTP Client, or URL Fetch on Google App Engine. It also features efficient JSON and XML data models for parsing and serialization of HTTP response and request content. The JSON and XML libraries are also fully pluggable, including support for Jackson and Android's GSON libraries for JSON.