Difference between HttpClientBuilder.create (). build (), HttpClients.createDefault () and DefaultHttpClient

3

When creating an Http connection using:

HttpClientBuilder.create().build(), HttpClients.createDefault()

or:

DefaultHttpClient .

What's the difference?

private static CloseableHttpClient httpClient = HttpClientBuilder.create().build();

private static CloseableHttpClient httpClient = HttpClients.createDefault();

private static DefaultHttpClient httpClient = new DefaultHttpClient();

Which one is right for you to use?

    
asked by anonymous 23.01.2015 / 14:16

1 answer

2

Come on,

  • HttpClients is an interface to assist you in creating classes that inherit from the abstract class CloseableHttpClient (In this case, it implements both the interface HttpClient and Closeable );
  • HttpClientBuilder is an auxiliary class that uses the Template if you prefer) project pattern creation of classes inheriting from CloseableHttpClient ;
  • DefaultHttpClient is a class that inherits from AbstractHttpClient , in which it inherits from CloseableHttpClient .
  • In addition, the build() and createDefault() method generates a DefaultHttpClient class. In short, everything is the same in different ways.

    I hope I have helped. : -)

        
    23.01.2015 / 18:28