Infinite redirect loop in HTTP request

When trying to get www.palringo.com

I get too many redirect redirection errors from URLConnection
    URL url = new URL("http://www.palringo.com/");      
    HttpURLConnection.setFollowRedirects(true);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    System.out.println("Response code = " + connection.getResponseCode());

displays scary:

Exception in thread "main" java.net.ProtocolException: Server redirected too many  times (20)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)

According to wget, there is only one redirect, from www.palringo.comtowww.palringo.com/en/gb/

Any ideas why my query using URLConnection for /en/gbresults in another 302 answer for the same resource?

The problem is illustrated:

    URL url = new URL("http://www.palringo.com/en/gb/");        
    HttpURLConnection.setFollowRedirects(false);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    // Just for testing, use Chrome header, to eliminate "anti-crawler" response!
    connection.setRequestProperty("User-Agent", "Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Ubuntu/11.04 Chromium/12.0.742.112 Chrome/12.0.742.112 Safari/534.30");
    System.out.println("Response code = " + connection.getResponseCode());

It is output:

Response code = 302
Redirected to /en/gb/

hence an infinite redirection loop.

Interestingly, browsers and wget handle this, curl doesn't work:

joel@bohr:/tmp$ curl http://www.palringo.com/en/gb/
curl: (7) couldn't connect to host

The request for is /en/gb/redirected to /en/gb/exactly once.

+5
source share
4 answers

, HttpURLConnection ( , - , Java) cookie.

cookie - .

: , cookie. - . cookie /, script .

: / cookie .

+12

, , /* → /en/gb , /en/gb, .

. ? - apache ? . , ( ) .

0

. Apache httpd rewrite, , . - . , .


.

.

, . "... , , robots.txt, . !".

, robots.txt. ToS , , , , .

, , wget ?

, , .


( ):

" :... xiii - , , Palringo".

, .

0

, , , .

0

All Articles