Regarding the class for connection org.apache.http.client.HttpClient
strong> as you comment, is currently obsolete, if you still need to use the class
HttpClient
, you can add this dependency in your
build.gradle
:
android {
useLibrary 'org.apache.http.legacy'
}
Although it is advisable to use the class HttpURLConnection if your target is Android 2.3 or higher (which is probably the case).
Example:
URL url = new URL("http://www.android.com/");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
try {
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
readStream(in);
finally {
urlConnection.disconnect();
}
}
To connect to an external database, you can do it through a Web Service ( Web Service
):
This is a tutorial in Spanish of an Android application, that consumes a Web Service
using HttpURLConnection, I hope it helps:
Consume Web Service on Android in a simple way