0

Doing the code above I have an arraylist with url images in objImages

Element table2 = document.select("TABLE").get(1); 
                Elements asWithName  = table2.select("tr>td a[name]");
                for (Element aWithName : asWithName) {
                    String name = aWithName.attr("name");
                    hostName.add(name);
                    Element tr = aWithName.parent().parent();
                    for (Element td : tr.select("td")){
                        Element img = td.select("img").first();
                        if (img == null){
                            continue;
                        }
                    String imgRelPath = img.attr("src");
                    images.add("http://hostname.com"+imgRelPath);
                    }
                    objImages = images.toArray(); 
                }
                objHostName = hostName.toArray();

Fine, I have the URLs. Now I have to get the images from those URLs and put it in imageView, each image in different imageView.

I was doing with:

for {int i=0; i<objImages.length; i++}
    InputStream input = new java.net.URL(objImages[i]).openStream();
    bitmap = BitmapFactory.decodeStream(input);
    ...
}

The problem is that http://hostname.com/hobbit/gifs/static/green.gif is protected by user/password (with .htaccess file).

But it doesn't work. Any idea?

Thanks in advance.

1 Answers1

0

Check this for basic authentication and this for downloading images with jsoup

In the end you will have something like this

String username = "foo";
String password = "bar";
String login = username + ":" + password;
String base64login = new String(Base64.encodeBase64(login.getBytes()));

Response resultImageResponse = Jsoup.header("Authorization", "Basic " + base64login)
                                    .connect(imageLocation).ignoreContentType(true).execute();

// output here
FileOutputStream out = (new FileOutputStream(new java.io.File(outputFolder + name)));
out.write(resultImageResponse.bodyAsBytes());  // resultImageResponse.body() is where the image's contents are.
out.close();
Community
  • 1
  • 1
Alkis Kalogeris
  • 17,044
  • 15
  • 59
  • 113