0

I need something that "download" the webpage content...I mean, I need to have the HTTP Response and store it into a String var.

For example If i insert www.example.com, the response will look like: <html><head></head><body>THIS IS AN EXAMPLE etc etc etc...<><><>

I tried some codes I saw, but they are from API < 23, and Android have removed HTTP APACHE.

THank you in advance

Parene
  • 15
  • 5

4 Answers4

1

HttpUrlConnection is the replacement for the apache libraries.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • @PaRiMaLRaJ Yes it does. He said the Apache libraries were removed in v23, so they can't be used. He was correct. I told him what API replaced them. – Gabe Sechan Mar 18 '16 at 16:14
  • It was exactly what I was looking for... thank you Gabe! – Parene Mar 25 '16 at 19:33
0

You can add

 useLibrary 'org.apache.http.legacy'

in gradle file and you can use HTTP Apache classes in API 23 +.

Shadab Ansari
  • 7,022
  • 2
  • 27
  • 45
0

you have two options: 1- use Android URLConnection for EX:

 URL url = new URL("http://www.example.com");
   URLConnection urlConnection = url.openConnection();
   InputStream in = new BufferedInputStream(urlConnection.getInputStream());
   try {
     readStream(in);
    finally {
     in.close();
   }
 }

2- add the following to your gradle file

 useLibrary 'org.apache.http.legacy'
0

Another alternative would be to use the OKHttp library.

Add this to your gradle file:

compile 'com.squareup.okhttp3:okhttp:3.2.0'

The library is relatively simple to use:

OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
      .url(url)
      .build();

Response response = client.newCall(request).execute();
String body = response.body().string();
Matt
  • 11,523
  • 2
  • 23
  • 33