0

I wonder why does this sample code:

public class Test {

    public static void main(String[] args) throws IOException {
        testLink("http://google.com");
        testLink("http://stackoverflow.com");
        testLink("http://docs.oracle.com");
    }

    private static void testLink(String urlStr) throws IOException
    {
        URL url = new URL(urlStr);

        HttpURLConnection conn = (HttpURLConnection)url.openConnection();
        conn.connect();
        System.out.println(conn.getResponseCode());
        conn.disconnect();
    }
}

Usually prints:

200
403
200

and not:

200
200
200
Lachezar Balev
  • 11,498
  • 9
  • 49
  • 72

1 Answers1

0

According to Wikipedia, a 403 response generally indicates one of two conditions:

Authentication was provided, but the authenticated user is not permitted to perform the requested operation.

The operation is forbidden to all users. For example, requests for a directory listing return code 403 when directory listing has been disabled.

So most probably connecting to SO via that User-Agent is forbidden.

Abhay Shukla
  • 349
  • 1
  • 12