'HttpParams & NameValuePair deprecated in Android Studio

I am currently developing a login and registration page using Android Studio. I am having issues with HttpParams and NameValuePair being deprecated. It's Android Studio 1.4. Is there libraries I can import for this?

@Override
    protected Void doInBackground(Void... params) {
        ArrayList<NameValuePair> dataToSend = new ArrayList<>();
        dataToSend.add(new BasicNameValuerPair("name", user.name));
        dataToSend.add(new BasicNameValuerPair("username", user.username));
        dataToSend.add(new BasicNameValuerPair("password", user.password));

        HttpParams httpRequestParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpRequestParams, CONNECTION_TIMEOUT);


Solution 1:[1]

Apache HTTP Client Removal Android 6.0 release removes support for the Apache HTTP client. If your app is using this client and targets Android 2.3 (API level 9) or higher, use the HttpURLConnection class instead. This API is more efficient because it reduces network use through transparent compression and response caching, and minimizes power consumption.

Here is an example to use the new class:

URL url = new URL("http://www.android.com/");
   HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
   try {
     InputStream in = new BufferedInputStream(urlConnection.getInputStream());
     readStream(in);
    finally {
     urlConnection.disconnect();
   }
}

To continue using the Apache HTTP APIs, you must first declare the following compile-time dependency in your build.gradle file:

android {
    useLibrary 'org.apache.http.legacy'
}

Solution 2:[2]

You have to add the dependencies of HttpClient in your build.gradle file:

android {

compileSdkVersion 23

buildToolsVersion "22.0.1"

useLibrary 'org.apache.http.legacy'

...

}

Solution 3:[3]

The Apache httpclient module that contains NameValuePair,DefaultHttpClient,HttpParams etc are deprecated from Android Api level 22 Lollipop 5.1 onwards, if you still want to use these deprecated classes in your project then add a line useLibrary 'org.apache.http.legacy' in your app's build.gradle file inside the android block as shown below and sync project

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
useLibrary 'org.apache.http.legacy'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wael Galal El Deen
Solution 2
Solution 3 Vaishakh