这段Android代码从InputStream读取内容到字符串。可以用于任何类型的InputStream,包括从HttpClient获取的HttpResponse
使用 inputStreamToString(response.getEntity().getContent())从HttpResponse 读取
// Fast Implementation private StringBuilder inputStreamToString(InputStream is) { String line = ""; StringBuilder total = new StringBuilder(); // Wrap a BufferedReader around the InputStream BufferedReader rd = new BufferedReader(new InputStreamReader(is)); // Read response until the end while ((line = rd.readLine()) != null) { total.append(line); } // Return full string return total; } // Slow Implementation from 75271.com private String inputStreamToString(InputStream is) { String s = ""; String line = ""; // Wrap a BufferedReader around the InputStream BufferedReader rd = new BufferedReader(new InputStreamReader(is)); // Read response until the end while ((line = rd.readLine()) != null) { s += line; } // Return full string return s; }