1

I have a simple method for retrieving raw HTML from internet URL, but every time i run it, i am getting java.net.SocketTimeoutException:

public static String getURL(String f) throws Exception{

    String k="", result="";

    URL url = new URL(f);

    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setConnectTimeout(10000); 
    conn.setRequestMethod("GET");       
    conn.connect();
    BufferedReader rd  = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    while ((k = rd.readLine()) != null) {
        result += k + "\n";
    }
    conn.disconnect(); 
    return result;
}  

This same code was working fine long time ago, i just copy pasted to reuse this method, but seems like something has changed over the time or may be there is something else.
I have double checked Java/Javaw are allowed in firewall exceptions but strange thing, all app's when try to get internet access, i get a prompt in my firewall, but with this there is nothing happening. Seems like program never trys to actually send a request while it timesout in the method.

Can someone suggest what could be the problem>?

Johnydep
  • 6,027
  • 20
  • 57
  • 74
  • 2
    Start by trying with a locally installed web server. It must have something to do with Java being blocked by the firewall. – JB Nizet Jan 21 '12 at 21:13
  • 1
    None of us have the ability to remotely sense your network configuration. It's clearly not to do with your code. – bmargulies Jan 21 '12 at 21:17
  • The following thread might be useful: http://stackoverflow.com/questions/693997/how-to-set-httpresponse-timeout-for-android-in-java – Nir Alfasi Jan 22 '12 at 00:17
  • @JBNizet, bmargulies, thank you. Yes i have tested, it works fine with local webserver. The strange thing is jvm never requests for internet access, since i deleted all firewall rules tried every other app requests for access, but jvm just never, seems like i have to a reinstall, strange? – Johnydep Jan 22 '12 at 00:35
  • @bmargulies, i don't know i have done everything, re installed java, reset the firewall (zone alarm), but somehow java on my machine can not go to internet, wondering what could be the reason? Last resort will be reinstalling the windows – Johnydep Jan 24 '12 at 21:01

0 Answers0