title: HTTP Error 400. The request has an invalid header name
body: <p>I have a Java application with the below code. I am trying to invoke a REST web service using HttpClient POST. I need to send a custom header "auth" for authentication. The value of the header is the encrypted credentials separated by a ":".</p>
  
  <pre><code>        String strAuth = DoAESEncrypt("userid:pwd");
          String strContent = DoAESEncrypt("{\"Name\":Tester,\"Id\":\"123\",\"NickName\":null,\"IsLocked\":false}");
  
            HttpClient client =  new DefaultHttpClient();          
            HttpPost post = new HttpPost("https://domainname/servicename");
            post.addHeader("auth",strAuth);
            post.addHeader("Content-Type", "application/json");
            StringEntity input = new StringEntity(strContent);
            post.setEntity(input);
            HttpResponse response = client.execute(post);
  </code></pre>
  
  <p>The DoAESEncrypt is a function that encrypts the input string and returns the Cipher. However, when I run this code, I get the below error where I have the statement client.execute:</p>
  
  <blockquote>
    <p>HTTP Error 400. The request has an invalid header name</p>
  </blockquote>
  
  <p>However, if I hard-code the below header with the encrypted Cipher I generated using the same DoAESEncrypt function, it works fine:</p>
  
  <pre><code>      post.addHeader("auth","5PE7vNMYVFJT/tgYo7TGuPO05lqMQx5w3BAJKDS567A73vM0TYFmWO5tP=");
  </code></pre>