title: How to Set HttpPost Headers for a Client Request in Java Android
body: <p>I am having trouble getting the Apache HttpClient to correctly send an HttpPost Header.</p>
  
  <p>I have no problems sending name value pairs and whatnot, but whenever I set or add a POST Header, it disappears when the request is made.</p>
  
  <p>I have tried both setHeader and addHeader, as well as trying both at once.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    HttpClient httpclient = new DefaultHttpClient();
      HttpPost httppost = new HttpPost("https://posttestserver.com/post.php");
      httppost.setHeader("Authorization: Bearer", accessToken);
      httppost.addHeader("Authorization: Bearer", accessToken);
      Log.d("DEBUG", "HEADERS: " + httppost.getFirstHeader("Authorization: Bearer"));
  
      ResponseHandler&lt;String&gt; responseHandler = new BasicResponseHandler();
      String responseBody = httpclient.execute(httppost, responseHandler);
  
      Log.d("DEBUG", "RESPONSE: " + responseBody);
  </code></pre>
  
  <p>Additionally, the debug statement before the request is executed prints out the correct header, so I know it is being added, then just dropped later.</p>
  
  <p>Any help would be much appreciated!</p>
  
  <p><strong>EDIT:</strong> This is all running inside of an AsyncTask if that matters.  I don't think it does since there is a NetworkOnMainThread exception thrown otherwise but I thought it might be worth mentioning.</p>