title: Android Volley POST request with header and body
body: <p>My code is trying to POST data to a server and I need to add a header, I am using the Volley library. </p>
  
  <p>The request works if I do not include the "getparams" method, I am able to post but with no data. </p>
  
  <p>If I include the "getparams" method, the request fails with a 400 (Bad request). </p>
  
  <p>I have not been able to find out where the error is.</p>
  
  <pre><code>         public void tryPost() {
      RequestQueue queue = Volley.newRequestQueue(this);
  
      String serverUrl = "http://10.0.2.2:3000/tasks";
  
  
  
      StringRequest stringRequest = new StringRequest(Request.Method.POST, serverUrl,
              new Response.Listener&lt;String&gt;() {
                  @Override
                  public void onResponse(String response) {
                      Log.d("TAG", "response = "+ response);
                  }
              }, new Response.ErrorListener() {
          @Override
          public void onErrorResponse(VolleyError error) {
              Log.d("TAG", "Error = "+ error);
          }
      })
      {
          //
          @Override
          public Map&lt;String, String&gt; getHeaders()  {
              HashMap&lt;String, String&gt; headers = new HashMap&lt;&gt;();
              headers.put("Accept", "application/json");
              headers.put("Content-Type", "application/json");
              return headers;
          }
          ////
          @Override
          public Map&lt;String, String&gt; getParams() {
              Map&lt;String, String&gt; params = new HashMap&lt;&gt;();
              params.put("userId","sargent"); 
              params.put("password","1234567"); 
              return params; //return the parameters
          }
      };
      // Add the request to the RequestQueue.
      queue.add(stringRequest);
      }
  </code></pre>