HttpClient deprecated (android studio, Target = api 22)

In my Android app, it says: org.apache.http.client.httpclient is deprecated. After some research, I found out that Android refused this in API 22. I searched the forum and tried: "Application stopped", "Google Search": "Application stopped." So I have no idea what to do. Hope you guys can help me. Well here is my code:

try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://www.URL.com"); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); Log.e("log_tag", "connection success"); // Toast.makeText(getApplicationContext(), "pass", Toast.LENGTH_SHORT).show(); } catch (Exception e) { Log.e("log_tag", "Error in http connection" + e.toString()); Toast.makeText(getApplicationContext(), "Connection fail", Toast.LENGTH_LONG).show(); 

EDIT:

I am trying to get some data from my Mysql database. Do you know a good tutorial on how to do this? Please let me know.

+6
source share
1 answer

Stop using it and use URLConnection instead. Google recommends this for 4 years. http://android-developers.blogspot.be/2011/09/androids-http-clients.html

If you need an external library with a more convenient API, you can try OkHttp: http://square.imtqy.com/okhttp/

+5
source

All Articles