httppparams , basicHttpParams , httpconnectionparams , defaulthttpclient deprecated

im deveolping anti theft application and found this connection class , but there were some deprecated things :

here the deperecated lines :
httppparams , basicHttpParams , httpconnectionparams , defaulthttpclient
How can i solve it ??
and here is a screenshot of the deprecated lines :

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.message.BasicNameValuePair;
 import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;

public class HttpRmi {

private HttpPost request = null;
private List<NameValuePair> nameValuePairs = null;
private int connectionTimeoutMillis = 300*1000;
private int socketTimeoutMillis = 0;
private HttpClient httpClient;

public HttpRmi(String url){
    request = new HttpPost(url);
    nameValuePairs = new ArrayList<NameValuePair>(1);
    HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams,       connectionTimeoutMillis);
    HttpConnectionParams.setSoTimeout(httpParams, socketTimeoutMillis);
    HttpProtocolParams.setContentCharset(httpParams, "utf-8");

    httpClient = new DefaultHttpClient(httpParams);

public HttpRmi add(String key, String value){
    nameValuePairs.add(new BasicNameValuePair(key, value));
    return this;

public String execute() throws IOException{
    String response = "";
        request.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8" )    );

        response = httpClient.execute(request, new BasicResponseHandler());
    }catch(Exception e){
        throw new IOException("no connection");

    return response;


The best alternatives to Httpclient are using OKHttp or HttpUrlConnection.

New applications should use HttpURLConnection; it is where we will be
spending our energy going forward. link

With HttpURLConnection


        String retFromServer = "";
        URL url;
        HttpURLConnection urlConnection = null;
        try {
            url = new URL(";
            urlConnection = (HttpURLConnection) url.openConnection();

            InputStream in = urlConnection.getInputStream();
            InputStreamReader inRead = new InputStreamReader(in);

            retFromServer = IOUtils.toString(inRead);
        } catch (Exception e) {
        } finally {
            if (urlConnection != null) {