Here you can find the source of readData(HttpURLConnection conn)
private static byte[] readData(HttpURLConnection conn)
//package com.java2s; //License from project: Apache License import java.io.*; import java.net.HttpURLConnection; public class Main { private static byte[] readData(HttpURLConnection conn) { BufferedInputStream in = null; try {//from w w w .j a v a 2s . c o m conn.connect(); int code = conn.getResponseCode(); in = new BufferedInputStream(conn.getInputStream()); int len; byte[] buffer = new byte[1024]; ByteArrayOutputStream out = new ByteArrayOutputStream(); while ((len = in.read(buffer)) != -1) { out.write(buffer, 0, len); out.flush(); } byte[] data = out.toByteArray(); out.close(); // for (int i = 0;; i++) { // String headerName = conn.getHeaderFieldKey(i); // String headerValue = conn.getHeaderField(i); // if (headerName == null && headerValue == null) { // break; // } // System.out.println(headerName + ":" + headerValue); // } return data; } catch (IOException e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } return null; } }