Avatar of Chris Jones
Chris Jones
Flag for United States of America asked on

import org.apache.http.HttpEntity; to legacy for android

Hello,

i have some android code that uses
import org.apache.http.HttpEntity;

i am trying to load the legacy code so my code will not have deprecated sections in it. i have updated the grande.build file and added the .jar files but the deprecated code still shows in my code.
Android

Avatar of undefined
Last Comment
Chris Harte

8/22/2022 - Mon
Chris Jones

ASKER
or is there a workaround to correct my function

    public void getData(){
        class GetDataJSON extends AsyncTask<String, Void, String>{

            @Override
            protected String doInBackground(String... params) {
                DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
                HttpPost httppost = new  HttpPost("http://hollyannjones.joneschris.info/get-data.php");

                // Depends on your web service
                httppost.setHeader("Content-type", "application/json");

                InputStream inputStream = null;
                String result = null;
                try {
                    HttpResponse response = httpclient.execute(httppost);
                    HttpEntity entity = response.getEntity();

                    inputStream = entity.getContent();
                    // json is UTF-8 by default
                    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
                    StringBuilder sb = new StringBuilder();

                    String line = null;
                    while ((line = reader.readLine()) != null)
                    {
                        sb.append(line + "\n");
                    }
                    result = sb.toString();
                } catch (Exception e) {
                    // Oops
                }
                finally {
                    try{if(inputStream != null)inputStream.close();}catch(Exception squish){}
                }
                return result;
            }

Open in new window

KRUNAL TAILOR

Hi Chris Jones,

useLibrary 'org.apache.http.legacy' in gradle. Download the jar file from here(https://hc.apache.org/downloads.cgi) and add into the project. Call webservice httpclient replace by httpurlconnection.

OR

Try other alternative (http://square.github.io/okhttp/), Here is what i am recommend you. I am using this in my projects.
 

Thanks & Regards,
Krunal T. Tailor
ASKER CERTIFIED SOLUTION
Chris Harte

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23