app/src/main/java/com/example/android/quakereport/QueryUtils.java
private static String makeHttpRequest(URL url) throws IOException
    {
        String jsonResponse = "";

        // If the URL is null, then return early.
        if (url == null) {
            return jsonResponse;
        }

        HttpsURLConnection urlConnection = null;
        InputStream inputStream = null;
        try {
            urlConnection = (HttpsURLConnection) url.openConnection();
            urlConnection.setReadTimeout(10000 /* milliseconds */);
            urlConnection.setConnectTimeout(15000 /* milliseconds */);
            urlConnection.setRequestMethod("GET");
            urlConnection.connect();

            // If the request was successful (response code 200),
            // then read the input stream and parse the response.
            if (urlConnection.getResponseCode() == 200) {
                inputStream = urlConnection.getInputStream();
                jsonResponse = readFromStream(inputStream);
            } else {
                Log.e(LOG_TAG, "Error response code: " + urlConnection.getResponseCode());
            }
        } catch (IOException e) {
            Log.e(LOG_TAG, "Problem retrieving the earthquake JSON results.", e);
        } finally {
            if (urlConnection != null) {
                urlConnection.disconnect();
            }
            if (inputStream != null) {
                inputStream.close();
            }
        }
        return jsonResponse;
    }
/**
     * Make an HTTP request to the given URL and return a String as the response.
     */
Make an HTTP request to the given URL and return a String as the response.
Make an HTTP request to the given URL and return a String as the response .
private static String makeHttpRequest(URL url) throws IOException
    {
        String jsonResponse = "";
        if (url == null) {
            return jsonResponse;
        }
        HttpsURLConnection urlConnection = null;
        InputStream inputStream = null;
        try {
            urlConnection = (HttpsURLConnection) url.openConnection();
            urlConnection.setReadTimeout(10000 /* milliseconds */);
            urlConnection.setConnectTimeout(15000 /* milliseconds */);
            urlConnection.setRequestMethod("GET");
            urlConnection.connect();
            if (urlConnection.getResponseCode() == 200) {
                inputStream = urlConnection.getInputStream();
                jsonResponse = readFromStream(inputStream);
            } else {
                Log.e(LOG_TAG, "Error response code: " + urlConnection.getResponseCode());
            }
        } catch (IOException e) {
            Log.e(LOG_TAG, "Problem retrieving the earthquake JSON results.", e);
        } finally {
            if (urlConnection != null) {
                urlConnection.disconnect();
            }
            if (inputStream != null) {
                inputStream.close();
            }
        }
        return jsonResponse;
    }
private static String makeHttpRequest ( URL url ) throws IOException { String jsonResponse = "" ; if ( url == null ) { return jsonResponse ; } HttpsURLConnection urlConnection = null ; InputStream inputStream = null ; try { urlConnection = ( HttpsURLConnection ) url . openConnection ( ) ; urlConnection . setReadTimeout ( 10000 /* milliseconds */ ) ; urlConnection . setConnectTimeout ( 15000 /* milliseconds */ ) ; urlConnection . setRequestMethod ( "GET" ) ; urlConnection . connect ( ) ; if ( urlConnection . getResponseCode ( ) == 200 ) { inputStream = urlConnection . getInputStream ( ) ; jsonResponse = readFromStream ( inputStream ) ; } else { Log . e ( LOG_TAG , "Error response code: " + urlConnection . getResponseCode ( ) ) ; } } catch ( IOException e ) { Log . e ( LOG_TAG , "Problem retrieving the earthquake JSON results." , e ) ; } finally { if ( urlConnection != null ) { urlConnection . disconnect ( ) ; } if ( inputStream != null ) { inputStream . close ( ) ; } } return jsonResponse ; }
Make an HTTP request to the given URL and return a String as the response.
Make an HTTP request to the given URL and return a String as the response .
// If the URL is null, then return early. // If the request was successful (response code 200), // then read the input stream and parse the response.