Java HTTP Response getResponseContent(HttpURLConnection connection)

Here you can find the source of getResponseContent(HttpURLConnection connection)

Description

get Response Content

License

Open Source License

Declaration

public static String getResponseContent(HttpURLConnection connection) throws IOException 

Method Source Code

//package com.java2s;
/**/*from ww w.j  a v a 2  s  .  c  o m*/
 * Copyright (C) 2010  BonitaSoft S.A.
 * BonitaSoft, 31 rue Gustave Eiffel - 38000 Grenoble
 * 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
 * version 2.1 of the License.
 * 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
 * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA  02110-1301, USA.
 **/

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;

public class Main {
    public static String getResponseContent(HttpURLConnection connection) throws IOException {
        InputStream is = connection.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String line;
        StringBuffer response = new StringBuffer();
        try {
            while ((line = reader.readLine()) != null) {
                response.append(line);
                response.append('\n');
            }
        } finally {
            reader.close();
            is.close();
        }
        return response.toString().trim();
    }
}

Related

  1. getResponse(HttpURLConnection httpConn, StringBuilder responseContent, StringBuilder responseCode, HashMap headers)
  2. getResponse(URL request)
  3. getResponse(URL url)
  4. getResponseAsString(HttpURLConnection conn)
  5. getResponseBody(HttpURLConnection conn)
  6. getResponseContent(HttpURLConnection httpConn)
  7. getResponseContent(String url)
  8. getResponseErrorContent(HttpURLConnection httpConn)
  9. getResponseHeader(HttpURLConnection conn)