Java HTTP Read getContent(final String urlString)

Here you can find the source of getContent(final String urlString)

Description

Gets the contents of a URL

License

Open Source License

Parameter

Parameter Description
urlString URL to get the contents of

Return

Contents of the URL

Declaration

public static String getContent(final String urlString) 

Method Source Code

//package com.java2s;
/*/*from   w  w  w. j a  v a  2 s  . c om*/
 * This file is part of SpaceModule (http://spacebukkit.xereo.net/).
 *
 * SpaceModule is free software: you can redistribute it and/or modify it under the terms of the
 * Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA) license as published by the Creative
 * Common organization, either version 3.0 of the license, or (at your option) any later version.
 *
 * SpaceBukkit is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA) license for more details.
 *
 * You should have received a copy of the Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA)
 * license along with this program. If not, see <http://creativecommons.org/licenses/by-nc-sa/3.0/>.
 */

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.net.URL;
import java.net.URLConnection;

public class Main {
    /**
     * Gets the contents of a URL
     * @param urlString URL to get the contents of
     * @return Contents of the URL
     */
    public static String getContent(final String urlString) {
        try {
            final URL url = new URL(urlString);
            final URLConnection urlConnection = url.openConnection();
            final BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
            String inputLine = "", content = "";
            while ((inputLine = reader.readLine()) != null)
                content += inputLine;
            reader.close();
            return content;
        } catch (final Exception e) {
        }
        return null;
    }
}

Related

  1. getByteaArrayFromConn(HttpURLConnection conn, boolean isSuccess)
  2. getContent(final HttpURLConnection con)
  3. getContent(String urlStr)
  4. getContentAsString(URL url)
  5. getContentEncoding(URL url)
  6. getContentFromHttpGetBasicAuth(String urlString, String username, String password)