Here you can find the source of getBodyResponse(HttpURLConnection con)
private static String getBodyResponse(HttpURLConnection con) throws IOException
//package com.java2s; /**/*from www . j a v a2 s . co m*/ * Copyright 2015 Telefonica Investigaci?n y Desarrollo, S.A.U * * This file is part of perseo-core project. * * perseo-core is free software: you can redistribute it and/or modify it under the terms of the GNU * General Public License version 2 as published by the Free Software Foundation. * * perseo-core 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 General Public License * for more details. * * You should have received a copy of the GNU General Public License along with perseo-core. If not, see * http://www.gnu.org/licenses/. * * For those usages not covered by the GNU General Public License please contact with * iot_support at tid dot es */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; public class Main { private static String getBodyResponse(HttpURLConnection con) throws IOException { int responseCode = con.getResponseCode(); InputStream stream; if (responseCode / 100 == 2) { stream = con.getInputStream(); } else { stream = con.getErrorStream(); } if (stream != null) { BufferedReader in = new BufferedReader(new InputStreamReader( stream)); String inputLine; StringBuilder response = new StringBuilder(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); return response.toString(); } return null; } }