Code example for HttpPost

Methods: addHeader, setEntity, setParams

0
	 *            if true return full list of results; only best match otherwise 
	 */ 
	public void sendPhoto(byte[] photo, Handler itraffApiHandler, boolean allResults) {
		try { 
			HttpPost postPhoto = getPostPhotoRequest(photo, allResults);
			ItraffApiPostPhoto postPhotoAsyncTask = new ItraffApiPostPhoto(itraffApiHandler, postPhoto, TAG, debug);
			postPhotoAsyncTask.execute();
		} catch (Exception e) {
			e.printStackTrace();
		} 
	} 
 
 
	/** 
	 * Sends photo to recognition server 
	 *  
	 * @param photo 
	 *            Bitmap image that is send through api 
	 * @param itraffApiHandler 
	 *            Handler used to return message from api 
	 */ 
	public void sendPhoto(byte[] photo, Handler itraffApiHandler) {
		sendPhoto(photo, itraffApiHandler, false);
	} 
 
	 
	private HttpPost getPostPhotoRequest(byte[] photo, boolean allResults) throws UnsupportedEncodingException {
		if (photo == null) return null;
		String requestUrl = customUrl;
		String paramsURL = "";
		if (mode.equals(MODE_MULTI)) {
			paramsURL = "multi/";
		} else if (allResults)
			paramsURL = "allResults/";
		if (requestUrl != null) {
			if (clientId != null){
				requestUrl += paramsURL + clientId;
			} 
			 
		} else { 
			if (clientId != null){
				requestUrl = API_URL + paramsURL + clientId;
			}else{ 
				requestUrl = API_URL + paramsURL;
			} 
		} 
 
		HttpPost postRequest = new HttpPost(requestUrl);
		log("Request url: " + requestUrl);
 
		HttpParams params = new BasicHttpParams();
	    HttpConnectionParams.setConnectionTimeout(params, 30000);
		postRequest.setParams(params);
 
		// create entity 
		HttpEntity entity = new ByteArrayEntity(photo);
		postRequest.setEntity(entity);
 
		// get hash MD5(clientKey+image) 
		String hash = ItraffApi.getMD5FromKeyAndImage(clientKey, photo);
 
		log("hash MD5(clientKey+image):"); 
		log(hash);
 
		Header header = new BasicHeader(HTTP.CONTENT_TYPE, "image/jpeg");
		postRequest.addHeader(header);
		header = new BasicHeader(HASH_HEADER, hash);
		postRequest.addHeader(header);
		header = new BasicHeader(ACCEPT, APPLICATION_JSON);
		postRequest.addHeader(header);
 
		return postRequest;
	} 
 
	/**