title: How to make the content-type: application/json in the apache httpPost method
body: <p>I am using the below code and it is showing the Content-Type:application/x-www-form-urlencoded, but I want this code to be Content-Type: application/json.
  Please suggest what changes needed to this code to make it an application/json request.</p>
  
  <pre><code>  private String baseUrl = "myIPAddress";
      private HttpClient client = new DefaultHttpClient();
      HttpPost post = new HttpPost(baseUrl + "app/registration");
              try {
                  String line = "";
                  for (int rIndex = 0; rIndex &lt; goodAuthenticationPairs.length; rIndex++) {
                      List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(
                              1);
                      nameValuePairs.add(new BasicNameValuePair("email","myEmail@test.com"));
                      nameValuePairs.add(new BasicNameValuePair("password","myPassword"));
                      post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                      //post.setHeader("Content-type", "application/json");
                      System.out.println(post);
                      HttpResponse response = client.execute(post);
                      BufferedReader rd = new BufferedReader(new InputStreamReader(
                              response.getEntity().getContent()));
                      line = rd.readLine();
                      System.out.println(line);
                      JSONObject json = (JSONObject) new JSONParser().parse(line);
                      String actualResult = json.get("return_code").toString();
  
                      assertTrue("0".equals(actualResult));
                  }
              } catch (IOException e) {
                  e.printStackTrace();
              } finally {
                  client.getConnectionManager().shutdown();
              }
  </code></pre>