Code example for HttpResponse

Methods: getFirstHeader

0
		return response.getStatusLine().getStatusCode();
	} 
	 
	/// get header of a http response 
	static String getHeader(HttpResponse response, String key) {
		Header header = response.getFirstHeader(key);
		if(header == null)
			return null; 
		else 
			return header.getValue();
	} 
	 
	/// read all http response body as a string 
	static String getBodyAsString(HttpResponse response) {
		try { 
	        ByteArrayOutputStream baos = new ByteArrayOutputStream();
	        byte[] buf = new byte[2048];
	        InputStream is = response.getEntity().getContent();
	        for(int i = 0; i != -1; i = is.read(buf))
	        	baos.write(buf, 0, i);
	        return Utilities.getUTF8String(baos.toByteArray());