i have problems with my http-headers. I need to send a post-request with an empty body and the header "Content-Length:0". But this seems impossible, becauce i get this exception:
--org.apache.http.ProtocolException: Content-Length header already present--
But when i do not include the header, there is no Content-Length header in the request and therefore i get 400: Bad Request. I build this in Python too and there it works fine, but i can not make it work in java. Can you help me, please?
Here is my Code:
HttpClient client = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader(header..);
httpPost.addHeader(another header);
httpPost.addHeader("Content-Type","application/xml");
httpPost.addHeader("Content-Length","0");
httpPost.addHeader(another header);
HttpResponse response = client.execute(httpPost);
System.out.println(response.getStatusLine().getStatusCode());
EDIT:
Solved the problem with the answer from @Beno Arakelyan.