HttpResponse to String android

HttpClient httpclient;
	HttpPost httppost;
	HttpResponse response;
httppost = new HttpPost("website-url-goes-here");
try {
				response = httpclient.execute(httppost);
				HttpEntity entity1 = response.getEntity();
				InputStream is = entity1.getContent();
				
				String w1url = convertStreamToString(is);
				
				
			} catch (ClientProtocolException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}

Add function into a class

private static String convertStreamToString(InputStream is) {

	    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
	    StringBuilder sb = new StringBuilder();

	    String line = null;
	    try {
	        while ((line = reader.readLine()) != null) {
	            sb.append((line + "\n"));
	        }
	    } catch (IOException e) {
	        e.printStackTrace();
	    } finally {
	        try {
	            is.close();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	    }
	    return sb.toString();
	}
Share