title: 500 Internal Server Error with POST Requests
body: <p>Here is my code for the POST request to the server.</p>
  
  <p>The JSON to be posted to the server :</p>
  
  <pre><code>{  
  "User": {    
  "Name": "dog","Password": "123"  }
  
  }
  </code></pre>
  
  <p>How I am creating the JSON Object</p>
  
  <pre><code>    object = new JSONObject();
      JSONObject jsonObject = new JSONObject();
      try {
          jsonObject.put("Name", "dog");
          jsonObject.put("Password", "123");
      } catch (JSONException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      try {
          object.put("User", jsonObject);
      } catch (JSONException e1) {
          // TODO Auto-generated catch block
          e1.printStackTrace();
      }
  </code></pre>
  
  <p>Posting to the server as</p>
  
  <pre><code>    public HttpResponse request(JSONObject request)
          throws ClientProtocolException, IOException, IllegalStateException,
              JSONException {
              client = (DefaultHttpClient) WebClientDevWrapper
                      .getNewHttpClient();
  
      HttpPost post = new HttpPost(
              "https://wbapi.cloudapp.net:443/api/User/LocalLogin/");
      post.setEntity(new StringEntity(request.toString(), "utf-8"));
      HttpResponse response = client.execute(post);
      return response;
  }
  </code></pre>
  
  <p>Along with classes provided by Paresh Mayani Here <a href="https://stackoverflow.com/questions/14051304/send-https-post-request-to-the-server">Send HTTPS Post Request to the server</a></p>
  
  <p>I am getting the response object. But my response.getStatusLine() keeps showing 500/ Internal server error for only POST requests.</p>
  
  <p>Note : GET requests are working fine.</p>
  
  <p>What is the Problem in my code ? How can I tackle this error ?</p>
  
  <p>Changed the request code as ( As recommended by Bhavdip Pathar)</p>
  
  <pre><code>public HttpResponse request(JSONObject request)
          throws ClientProtocolException, IOException, IllegalStateException,
          JSONException {
  
      HttpPost post = new HttpPost(
              "https://wbapi.cloudapp.net:443/api/User/LocalLogin/");
      // post.setEntity(new StringEntity(request.toString(), "utf-8"));
      StringEntity entity = new StringEntity(request.toString(), HTTP.UTF_8);
      entity.setContentType("application/json");
      post.setHeader("Content-Type", "application/json");
      post.setHeader("Accept", "application/json");
      post.setEntity(entity);
      HttpResponse response = client.execute(post);
      return response;
  }
  </code></pre>
  
  <p>I did set application/json and voila , I am getting HTTP/200 OK.</p>