Reputation: 3512
In process to develop a plugin to copy the images from various web pages, I am trying to get the image from URLs in my java code like below:
URL urlString = new URL("http://www.hdwallsource.com/img/2014/7/harley-davidson-wallpaper-16885-17439-hd-wallpapers.jpg");
URLConnection conn = urlString.openConnection();
System.out.println("--------------------getContentType: "+conn.getContentType()+"....conn:"+conn);
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
System.out.println("--------------------"+in);
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
For this particular image path: "http://www.hdwallsource.com/img/2014/7/harley-davidson-wallpaper-16885-17439-hd-wallpapers.jpg" I am getting getContentType: text/html; charset=UTF-8. and my sysout is giving me all HTML code of the page where this image is available. For all other images path like: http://img6a.flixcart.com/image/mobile/n/q/a/motorola-moto-g-400x400-imadsmbwhznhucjj.jpeg I am getting proper image/jpeg type and image content. Any help will be appreciated.
Upvotes: 0
Views: 88
Reputation: 1357
If you open the first link in new incognito window of your browser you will find out that you get html page as well. The site probably has some policy of not showing images to crawlers. It seems that if you don't have the site's cookies they will show you the html page.
Upvotes: 2