-1

i am using android studio 1.5.1 API 23, when we use "HttpParams" in a java programme we got some error like we can not use it in this version so how i can include it in my android studio ?

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



        /*URL url = new URL(SERVER_ADDRESS +"Register.php");
        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet();
        request.setURI(new URI(link));*/
        //HttpParams httpParams = new BasicHttpParams();
        HttpParams httpRequestParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpRequestParams, CONNECTION_TIMEOUT);


        HttpClient client = new DefaultHttpClient(httpRequestParams);
        HttpPost post = new HttpPost(SERVER_ADDRESS +"Register.php");

       try{
            post.setEntity(new UrlEncodedFormEntity(dataToSend));
           client.execute(post);
        }catch (Exception e){
            e.printStackTrace();

        }


        return null;
    }

1 Answers1

1

API level 23 removed support for the Apache HTTP client.

If you really need to use the Apache HTTP classes, you can do so by including this in your build.gradle:

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

However, you should do so only as a last resort. Instead you should look into options for migrating off of the Apache HTTP client.

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120