title: 400 - Bad Request on Apache POST sending JSON
body: <p>I'm trying to make a REST call from my class using the Apache. But its giving the 400 exception when I print the response of the REST service. Kindly find the code below and let me know the changes that needs to be made to make it working,</p>
  
  <pre><code>    List&lt;NameValuePair&gt; pickup = new ArrayList&lt;NameValuePair&gt;();
      ArrayList&lt;HashMap&gt; pickupItemList = new ArrayList&lt;HashMap&gt;();
  
      String [] productIds = prop.getArray("vproductIDs");
      String [] quantities = prop.getArray("vquantities");
      String [] tprices = prop.getArray("vtprices");
      String [] bprices = prop.getArray("vbprices");
  
      HashMap pickupObjMap = new HashMap&lt;String, Object&gt;();
      pickupObjMap.put("loyaltyId",prop.getString("loyaltyId"));
      pickupObjMap.put("loyaltyFName",prop.getString("loyaltyFName"));
      pickupObjMap.put("orderId",prop.getString("orderId"));
      pickupObjMap.put("locationId",prop.getString("locationId"));
      pickupObjMap.put("consignmentId",prop.getString("consignmentId"));
      pickupObjMap.put("description",prop.getString("description"));
      pickupObjMap.put("retailerId",prop.getString("retailerId"));
      pickupObjMap.put("pickupType",Integer.parseInt(prop.getString("pickupType")));
      pickupObjMap.put("email",prop.getString("email"));
      pickupObjMap.put("loyaltyLName",prop.getString("loyaltyLName"));
      pickupObjMap.put("status",prop.getString("status"));
  
      for(int i=0; i&lt;productIds.length ; i++){
          HashMap map = new HashMap&lt;String, Object&gt;();
          map.put("sku", productIds[i]);
          map.put("quantity", Double.parseDouble(quantities[i]));
          map.put("totalPrice", Double.parseDouble(tprices[i]));
          map.put("basePrice", Double.parseDouble(bprices[i]));
          pickupItemList.add(map);
      }
      pickup.add(new BasicNameValuePair("pickupItemList", pickupItemList.toString()));
      pickup.add(new BasicNameValuePair("pickupObj", pickupObjMap.toString()));
      pickup.add(new BasicNameValuePair("ovclid", prop.getString("ovclid")));
  
          HttpPost httppost = new HttpPost("Target URL");
          try {
              httppost.setEntity(new UrlEncodedFormEntity(pickup));
              httppost.setHeader("Content-Type", "application/json");
              HttpClient httpclient = new DefaultHttpClient();
              HttpResponse response = httpclient.execute(httppost);
              HttpEntity entity = response.getEntity();
              BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent()));
              if (bufferedReader != null) {
                  int cp;
                  StringBuilder sb = new StringBuilder();
                  while ((cp = bufferedReader.read()) != -1) {
                      sb.append((char) cp);
                  }
                  System.out.println("String Response......."+sb);
                  bufferedReader.close();
              }
              System.out.println("Response......."+entity.getContent());
          } catch (Exception e) {
              e.printStackTrace();
  
          }
  </code></pre>
  
  <p>Below is the response that I get upon making the REST Call.</p>
  
  <pre><code>Unexpected character ('p' (code 112)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') 
  at [Source: org.glassfish.jersey.message.internal.EntityInputStream@175d5e8a; line: 1, column: 2]
  </code></pre>