1

I'm a little confused with exactly what's going on with this request. As you can see by clicking on the link with a standard browser, the item image displays fine with a 200 response code. (This can be seen by opening the developer tools in the network section of most browsers.) However, I wrote a script that will ping the URL for the response code using standard Java classes, and I'm getting a 403 Forbidden response code:

static public void main(String[] args) throws IOException
{
    URL my_url = new URL("http://www.gessi.it/static/images/products/zoom/01410.png");

    URLConnection u = my_url.openConnection();

    if (u instanceof HttpURLConnection)
    {
        HttpURLConnection http_u = (HttpURLConnection) u;

        System.out.println("Response code: " + http_u.getResponseCode());
        System.out.println("Response message: " + http_u.getResponseMessage());
    }
}

Does anyone know why the script would receive the forbidden code, while standard browsers can view the image just fine? In the past, I've seen some image fetches fail with my scripts, because Java can't natively handle complicated 302 redirects and such, but there's none of that in this case.

Sal
  • 3,179
  • 7
  • 31
  • 41

1 Answers1

2
http_u.setRequestProperty("User-Agent", "Mozilla 9.10");

The server looks for the User-Agent request header so it does not need to serve crawlers, harvesters and the like.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138