Code example for HttpURLConnection

Methods: connect, getResponseCode, setConnectTimeout, setRequestProperty

0
    protected boolean pingNuxeoServer() { 
        try { 
            URL url = new URL(getServerConfig().getServerBaseUrl()
                    + "login.jsp"); 
            HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
            urlc.setRequestProperty("User-Agent", "Nuxeo Android Application");
            urlc.setRequestProperty("Connection", "close");
            urlc.setConnectTimeout(1000 * 15); // mTimeout is in seconds
            urlc.connect();
            if (urlc.getResponseCode() == 200) {
                return true; 
            } else { 
                return false; 
            } 
        } catch (Exception e) {
            Log.e(TAG, "Connection to Nuxeo server failed: " + e.getMessage());
            Log.d(TAG, e.getMessage(), e);
            return false; 
        } 
    }