Depending on what you are trying to achieve this may be a lost cause. Having an Internet Connection 1 second does not mean you will have it the next (think mobile, spotty networks, dropped packets, tunnels, congested conference/airport wifi etc.)
You are better off to make an asynchronous request for the resource you want... if it works... Giddy Up!... if it fails, or times out, then deal with that scenario.