5

When I have written following piece of code to check whether the site is up or not I always get http 503, even though the site is working fine when I hit it on browser.

URL url=getASCIIUrl(httpUrl);
HttpURLConnection con = null;
    con = (HttpURLConnection) url.openConnection();
                HttpURLConnection.setFollowRedirects(false);
                con.setRequestMethod("GET");
                con.setConnectTimeout(CONNECTION_TIMEOUT);
                con.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.01; WiPOSTndows NT 5.0)");
                int code = con.getResponseCode();

Everytime I get Http 503 in responsecode. Can anyone suggest a way to overcome this problem?

  • In the user-agent you have `WiPOSTndows`. Is this supposed to be there (it probably doesn't matter...)? And more importantly, is the `POST` supposed to be elsewhere? – DavidW Apr 27 '15 at 06:43
  • 1
    Ok, now i have changed the "user-Agent" to "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)" this. And I don't understand about your POST query. – Sunny Gujarati Apr 27 '15 at 10:02
  • I have no reason to believe there should be a `POST` in there, except that you'd accidentally put one in somewhere odd! It's probably nothing to do with the problem... – DavidW Apr 27 '15 at 15:52
  • I too am experiencing this problem. My groovy script is as simple as: println new URL(healthCheckUrl).text and it gets 503. But when I put the URL into my browser, it works just fine. Sad to see there isn't a solution for this yet – Achilles929 Apr 11 '19 at 14:08

0 Answers0