Answer the question
In order to leave comments, you need to log in
How to send http request in android?
Hello everyone, after a long search, I have a question, in the latest Android studio I don’t see the httpClient methods, etc.
public static String GET(String url){
InputStream inputStream = null;
String result = "";
try {
// create HttpClient
HttpClient httpclient = new DefaultHttpClient();
// make GET request to the given URL
HttpResponse httpResponse = httpclient.execute(new HttpGet(url));
// receive response as inputStream
inputStream = httpResponse.getEntity().getContent();
// convert inputstream to string
if(inputStream != null)
result = convertInputStreamToString(inputStream);
else
result = "Did not work!";
} catch (Exception e) {
Log.d("InputStream", e.getLocalizedMessage());
}
return result;
}
Answer the question
In order to leave comments, you need to log in
Removed
HTTPClient from Android version 6 .
Try to write in build.gradle:
android {
useLibrary 'org.apache.http.legacy'
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question