Question

I want to download images from other websites that are hotlink protected. I don't want to link those images to my website. I just wanted to download them.

Was it helpful?

Solution

The usual hotlink-protection method checks if the "Referrer" HTTP Header matches the domain name of the original website.

You can easily bypass that by setting that header manually to point to a page in the website.

OTHER TIPS

You need to pass the referrer http header. You can do this with wget on most unix systems as follows:

wget --referer=http://www.google.com/ http://www.google.com/intl/en_ALL/images/logo.gif

Here a raw way to do it so you see exactly what is going on:

telnet google.com 80
GET /intl/en_ALL/images/logo.gif HTTP/1.1
REFERER: http://www.google.com/
HOST: www.google.com

You can download hotlink protected images by using the following code:

URL url = new URL("http://www.somesite.com/picture.jpg");

URLConnection urlCon = url.openConnection();
urlConn.setRequestProperty("Referer", "http://www.somesite.com");
urlConn.connect();

InputStream urlStream = urlCon.getInputStream();

Image image = ImageIO.read(urlStream);

The Postman extension for Chrome lets you make custom http requests. I found a hotlink-blocked image, copied it's url and entered it into Postman to GET it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top