title: JAX-RS client, ProtocolException: Content-Length header already present
body: <p>I have the following method:</p>
  
  <pre><code>private static final String UTF_8 = "UTF-8";
  private static final int TIMEOUT = 5000;
  private static final String DATASTREAM_URI = "MY_VALID_URL_HERE";
  
  @Override
  public Response logHttpMessage(final String logHttpMessageXml) throws UnsupportedEncodingException {
  
      final Client client = new ResteasyClientBuilder()
              .establishConnectionTimeout(TIMEOUT, TimeUnit.MILLISECONDS)
              .socketTimeout(TIMEOUT, TimeUnit.MILLISECONDS)
              .build();
  
      final WebTarget target = client.target(DATASTREAM_URI);
      return target.request().header(HttpHeaders.CONTENT_LENGTH, logHttpMessageXml.getBytes(UTF_8).length)
              .post(Entity.entity(logHttpMessageXml, MediaType.APPLICATION_XML_TYPE));
  }
  </code></pre>
  
  <p>I add the header by doing the following: 
  <strong>.header(HttpHeaders.CONTENT_LENGTH, logHttpMessageXml.getBytes(UTF_8).length)</strong></p>
  
  <p>But I get this error when doing the request:</p>
  
  <p><img src="https://i.stack.imgur.com/62Dl8.png" alt="enter image description here"></p>
  
  <p>NOTE: I need to set the content length in order to disallow chunking, my rest endpoint (out of my control) does NOT react correctly to chunked data.</p>
  
  <p>I´ve been searching the web but did not find a solution, how can I solve this? Thanks in advance!</p>