I played a bit with your URL with telnet, wget, and curl and I noticed that in some cases the server returns response 200 OK
, and sometimes 302 Moved Temporarily
. The main difference seems to be the request User-agent header. Your code works if you add the following before con1.connect()
:
con1.setRequestProperty("User-Agent","");
That is, with empty User-Agent (or if the header is not present at all), the server issues a redirect. With the Java User-Agent (in my case User-Agent: Java/1.7.0_45
) and with the default curl User-Agent (User-Agent: curl/7.32.0
) the server responds with 200 OK.
In some cases you might need to also set:
System.setProperty("http.agent", "");
See Setting user agent of a java URLConnection
The server running the site is the Adtech Adserver and apparently it is doing user agent sniffing. There is a long history of user agent sniffing. So it seems that the safest thing to do would be to set the user agent to Mozilla:
con1.setRequestProperty("User-Agent","Mozilla"); //works with your code for your URL
Maybe the safest option would be to use a user agent used by some of the popular web browsers.