'how to send Content-Length in rest assure ,Since encountering error that "Content-Length header already present"

I am performing post operation using RestAssure and where in header I am passing Content-Length as below - queryParam().header("Content-Length", "value_Of_It")

and due to that, I am encountering the error that "Content-Length header already present". it would be great if someone can help me out to resolve it ?

Caused by: org.apache.http.ProtocolException: Content-Length header already present

And below are the headers gets added in postman by default,So while automating in Rest Assure d i need t pass them if not then how to resolve since getting 400 Bad request ? -

enter image description here



Solution 1:[1]

Rest-Assured automatically add Content-Length to header when doing the POST request. I've already tested with Postman proxy to see all information in Rest-Assured request.

Code:

given().proxy(5555)
       .body("test")
       .post("http://postman-echo.com/post");

enter image description here

If I add another Content-Length, I will get the same error as yours.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 lucas-nguyen-17