Java HTTP Response getResposeText(HttpURLConnection connection)

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

Description

get Respose Text

License

Apache License

Declaration

public static String getResposeText(HttpURLConnection connection) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static String getResposeText(HttpURLConnection connection) throws IOException {
        InputStream is = connection.getInputStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        int len;/*from w w  w  .java2s  . c  o  m*/
        while ((len = is.read(buffer)) > 0) {
            baos.write(buffer, 0, len);
        }
        String responseText = baos.toString("UTF8");
        return responseText;
    }
}

Related

  1. getResponseMessage(InputStream inputStream, HttpURLConnection connection)
  2. getResponseStream(final HttpURLConnection connection)
  3. getResponseStream(HttpURLConnection conn)
  4. getResponseStringFromConn(HttpURLConnection conn, boolean isSuccess)
  5. getResponseText(URL constructedUrl, String encoding)
  6. readResponse(HttpURLConnection conn, String encoding)
  7. readResponse(HttpURLConnection connection)
  8. readResponse(HttpURLConnection httpURLConnection)
  9. readResponse(URLConnection conn)