Code example for HttpPut

Methods: setEntity, setHeader

0
                        int fat,
                        int carbs) {
                String service = server + "/api/dishes/create";
             
                HttpClient httpclient = new DefaultHttpClient();
            HttpPut httpput = new HttpPut(service);
 
            try { 
                httpput.setHeader("Accept", "application/json");
                // Add your data 
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
//              nameValuePairs.add(new BasicNameValuePair("dishId", Long.toString(dishId))); 
//              nameValuePairs.add(new BasicNameValuePair("recommended", Boolean.toString(recommended))); 
                nameValuePairs.add(new BasicNameValuePair("restaurantId", restaurantId));
                nameValuePairs.add(new BasicNameValuePair("franchiseId", franchiseId));
                nameValuePairs.add(new BasicNameValuePair("title", title));
                nameValuePairs.add(new BasicNameValuePair("description", description));
                nameValuePairs.add(new BasicNameValuePair("calories", Integer.toString(calories)));
                nameValuePairs.add(new BasicNameValuePair("protein", Integer.toString(protein)));
                nameValuePairs.add(new BasicNameValuePair("fat", Integer.toString(fat)));
                nameValuePairs.add(new BasicNameValuePair("carbs", Integer.toString(carbs)));
                httpput.setEntity(new UrlEncodedFormEntity(nameValuePairs));
 
                // Execute HTTP Post Request 
                HttpResponse response = httpclient.execute(httpput);
                HttpEntity entity = response.getEntity();
                        String result = EntityUtils.toString(entity);   
                        Log.d(ERAService.class.getName() + ".createDish()", result);
                        Dish dish = gson.fromJson(result, Dish.class);
                        return dish;