0

I'm trying to get page content from a specific URL:

HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
LOGGER.info("Response code: "+conn.getResponseCode();
... (rest of the code, not relevant at the moment) ...

I'm not able to get conn.getResponseCode(), I have timeout before it gets printed. Surprisingly, when I put the very same URL in my browser, the page will be loaded correctly. I thought it may have something do to with HTTP/HTTPS, unfortunately, after changing HttpURLConnection to HttpsURLConnection there is no difference.

Maybe it has something to do with JBoss configuration? I use JBoss 7.1.1 Final.

pzeszko
  • 1,989
  • 18
  • 29
  • 1
    Have you tried this with other URLs? If the URL isn't something sensitive, it'd help if I could test it. Right now, with a random http url, your above code is giving me a 200 OK as expected. – Christopher Wirt Jun 23 '15 at 18:53
  • Thanks for your suppourt. Unfortunately, it looks like none URL works fine. I guess it may be the JBoss configuration issue. I will try this on my another server. – pzeszko Jun 23 '15 at 19:04
  • 2
    Is this server behind a HTTP proxy? Use of of proxies in your browser can be transparent, so you may not notice their presence. – Steve C Jun 24 '15 at 01:39
  • Actually, there are multiple servers and we have a load balancer. I guess it may be the issue. – pzeszko Jun 26 '15 at 08:12

1 Answers1

0

Is this an HTTPS url? If it is, you need to account for that. When using an HttpsURLConnection, you must account for the fact that HTTPS certificates need a truststore to compare against. To ignore this sense of trust (and somewhat ruin the point of using HTTPS), see Whats an easy way to totally ignore ssl with java url connections?

Community
  • 1
  • 1
Christopher Wirt
  • 1,108
  • 1
  • 10
  • 21