Apache HttpClient

Apache HttpClient
The Apache HttpClient library allows us to make HTTP requests.

  • Add HttpClient Library to your project

For latest Version:-  https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient

  • Creating HTTP Client and HTTP Post

  • Building Post Parameters:- The following code will create post parameters pair with key and value.

  • URL Encoding POST data:-Before making HTTP request you need to encode the post data in order to convert all string data into valid URL format.

  • Finally you need to execute httpPost using the httpClient created before.

 

Complete Code

Download Complete Code

Note:

  • It is recommended to use OkHttp instead of HttpClient.
  • For the sake of simplicity, we haven’t use any thread here. Don’t make any network call in UI thread.

Also, Refer

1) https://www.androidhive.info/2011/10/android-making-http-requests/

2) http://www.vogella.com/tutorials/ApacheHttpClient/article.html

Posted in Android.