DefaultHttpClient is decrepated in Android app

0

I'm performing an integration with a JSON in my application, but when I use DefaultHttpClient it displays the message:

  

'org.apache.http.impl.client.DefaultHttpClient' is deprecated.

Follow the code below:

public class JsonClass {

    InputStream input = null;
    JSONObject jObect = null;
    String json = "";

    //Recebe sua url
    public JSONObject getJSONFromUrl(String url) {

        //HTTP request
        try {
            // default HttpClient
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);

            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            input = httpEntity.getContent();

        } catch (UnsupportedEncodingException | ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    input, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            input.close();
            json = sb.toString();
            Log.i("JRF", json);
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }

        // Transforma a String de resposta em um JSonObject
        try {
            jObect = new JSONObject(json);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }

        // retorna o objeto
        return jObect;

    }
}

In some classes such as DefaultHttpClient , HttpPost , HttpResponse and etc, they appear streaked in code, and display this message.

    
asked by anonymous 04.05.2015 / 16:31

0 answers