title: HTTP POST request with authorization on android
body: <p>When I set "Authorization" header with setHeader from HttpPost then hostname disappears from request and there is always error 400 (bad request) returned. Same code is working fine on pure java (without android) and when I remove setting "Authorization" header also on android it works fine, but I need authorization.
  This is a code (domain changed):</p>
  
  <pre><code>HttpClient client = new DefaultHttpClient();
  HttpPost post = new HttpPost("http://myhost.com/test.php");
  post.setHeader("Accept", "application/json");
  post.setHeader("User-Agent", "Apache-HttpClient/4.1 (java 1.5)");
  post.setHeader("Host", "myhost.com");
  post.setHeader("Authorization",getB64Auth());
  List &lt;NameValuePair&gt; nvps = new ArrayList &lt;NameValuePair&gt;();
  nvps.add(new BasicNameValuePair("data[body]", "test"));
  AbstractHttpEntity ent=new UrlEncodedFormEntity(nvps, HTTP.UTF_8);
  ent.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
  ent.setContentEncoding("UTF-8");
  post.setEntity(ent);
  post.setURI(new URI("http://myhost.com/test.php"));
  HttpResponse response =client.execute(post);
  </code></pre>
  
  <p>Method getB64Auth() returns "login:password" encoded using Base64 like: "YnxpcYRlc3RwMTulHGhlSGs=" but it's not important.</p>
  
  <p>This is a piece of lighttpd's error.log when above code is invoked on pure java:</p>
  
  <pre><code>2011-02-23 15:37:36: (request.c.304) fd: 8 request-len: 308
  POST /test.php HTTP/1.1
  Accept: application/json
  User-Agent: Apache-HttpClient/4.1 (java 1.5)
  Host: myhost.com
  Authorization: Basic YnxpcYRlc3RwMTulHGhlSGs=
  Content-Length: 21
  Content-Type: application/x-www-form-urlencoded; charset=UTF-8
  Content-Encoding: UTF-8
  Connection: Keep-Alive
  
  HTTP/1.1 200 OK
  Content-type: text/html
  Transfer-Encoding: chunked
  </code></pre>
  
  <p>and record from access.log (IP changed):</p>
  
  <pre><code>1.1.1.1 myhost.com - [23/Feb/2011:15:37:36 +0100] "POST /test.php HTTP/1.1" 200 32 "-" "Apache-HttpClient/4.1 (java 1.5)"
  </code></pre>
  
  <p>When the same code is invoked on android, I get this in logs:</p>
  
  <pre><code>POST /test.php HTTP/1.1
  Accept: application/json
  User-Agent: Apache-HttpClient/4.1 (java 1.5)
  Host: myhost.com
  Authorization: Basic YnxpcYRlc3RwMTulHGhlSGs=
  
  Content-Length: 21
  Content-Type: application/x-www-form-urlencoded; charset=UTF-8
  Content-Encoding: UTF-8
  Connection: Keep-Alive
  Expect: 100-Continue
  
  
  2011-02-23 15:45:10: (response.c.128) Response-Header:
  HTTP/1.1 400 Bad Request
  Content-Type: text/html
  Content-Length: 349
  Connection: close
  </code></pre>
  
  <p>access.log:</p>
  
  <pre><code>1.1.1.1 - - [23/Feb/2011:15:45:10 +0100] "POST /test.php HTTP/1.1" 400 349 "-" "Apache-HttpClient/4.1 (java 1.5)"
  </code></pre>
  
  <p>How to get Authorization with POST working on android?
  When I use HttpURLConnection instead of HttpClient it is no difference.</p>