Java URL Read getHTTPResponse(String url)

Here you can find the source of getHTTPResponse(String url)

Description

get HTTP Response

License

Open Source License

Declaration

public static String getHTTPResponse(String url) throws IOException 

Method Source Code

//package com.java2s;
/**/*from  w w w .  j a v  a2  s . co  m*/
 * Helix
 * Copyright (c) Matheus Vigaro <matheus@vigaro.tk>, All rights reserved.
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3.0 of the License, or (at your option) any later version.
 * This library 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 GNU
 * Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.
 **/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import java.util.zip.GZIPInputStream;

public class Main {
    public static String getHTTPResponse(String url) throws IOException {
        HttpURLConnection con = (HttpURLConnection) (new URL(url))
                .openConnection();
        BufferedReader reader = new BufferedReader(
                new InputStreamReader("gzip".equals(con
                        .getContentEncoding()) ? new GZIPInputStream(
                        con.getInputStream()) : con.getInputStream()));
        StringBuilder response = new StringBuilder();
        String l;

        while ((l = reader.readLine()) != null) {
            response.append(l);
            response.append('\r');
        }

        reader.close();
        return response.toString();
    }
}

Related

  1. getHtml(String url)
  2. getHtml(String urlString)
  3. getHTML(String urlToRead)
  4. getHTML(String urlToRead)
  5. getHttpResponse(HttpURLConnection conn, int expectedReturnCode)
  6. getHttpResponse(String urlStr)
  7. getLastModified(HttpURLConnection conn)
  8. getLastModified(HttpURLConnection connection)
  9. getRemoteFileLength(String url)