Java HTTP Response readResponse(HttpURLConnection conn, String encoding)

Here you can find the source of readResponse(HttpURLConnection conn, String encoding)

Description

read Response

License

Apache License

Declaration

private static String readResponse(HttpURLConnection conn,
            String encoding) 

Method Source Code

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

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 readResponse(HttpURLConnection conn,
            String encoding) {//from ww w  .j  a  v  a  2  s .com
        StringBuffer sb = new StringBuffer();
        BufferedReader br = null;

        try {
            InputStream in = conn.getInputStream();
            br = new BufferedReader(new InputStreamReader(in));
            String line = "";
            while ((line = br.readLine()) != null) {
                sb.append(line);
            }
            in.close();
            br.close();
            conn.disconnect();

            return new String(sb.toString());
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related

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