Code example for HttpPost

Methods: getParams, setEntity

0
			int monthOfYear, int dayOfMonth, int mealId)
			throws OAuthMessageSignerException, 
			OAuthExpectationFailedException, ClientProtocolException, 
			IOException, OAuthNotAuthorizedException { 
		// create a request that requires authentication 
		HttpPost post = new HttpPost(
				"https://dailyburn.com/api/food_log_entries"); 
		final List<NameValuePair> nvps = new ArrayList<NameValuePair>();
		// 'status' here is the update value you collect from UI 
		nvps.add(new BasicNameValuePair("food_log_entry[food_id]", String
				.valueOf(foodId)));
		nvps.add(new BasicNameValuePair("food_log_entry[servings_eaten]",
				servings_eaten));
		GregorianCalendar cal = new GregorianCalendar(year, monthOfYear,
				dayOfMonth);
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		String formattedDate = format.format(cal.getTime());
		nvps.add(new BasicNameValuePair("food_log_entry[logged_on]",
				formattedDate));
		nvps.add(new BasicNameValuePair("food_log_entry[meal_name_id]", String
				.valueOf(mealId)));
		post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
		// set this to avoid 417 error (Expectation Failed) 
		post.getParams().setBooleanParameter(
				CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
		// sign the request 
		consumer.sign(post);
		// send the request 
		final HttpResponse response = client.execute(post);
		// response status should be 200 OK 
		int statusCode = response.getStatusLine().getStatusCode();
		final String reason = response.getStatusLine().getReasonPhrase();
		// release connection 
		response.getEntity().consumeContent();