implementation 'org.apache.httpcomponents:httpclient:4.5.13'
<uses-permission android:name="android.permission.INTERNET" />
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://example.com/api/data");
try {
HttpResponse httpResponse = httpClient.execute(httpGet);
String responseBody = EntityUtils.toString(httpResponse.getEntity());
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();