Reputation: 31
I'm pretty new to Java and REST/REST assured. I'm trying to create a POST Request with "Transfer-Encoding: chunked" set (via a Header) but I get the exception “org.apache.http.ProtocolException: Transfer-encoding header already present”.
The code I'm using is similar to the following ..... @Test ...... given() .headers(uses a method that sets the required headers, including "Transfer-encoding") .body("testdata".getBytes()) .contentType(MediaType.APPLICATION_OCTET_STREAM) .log().all() .expect() .statusCode(HttpStatus.SC_OK) .post();
but I get the exception "org.apache.http.ProtocolException: Transfer-encoding header already present”.
Does anyone have an idea why i'm getting the exception / how i can resolve it?? Thanks in advance.
Upvotes: 3
Views: 2201
Reputation: 590
Yesterday I able to use octate stream
given().urlEncodingEnabled(false)
.config(RestAssured.config()
.encoderConfig(new EncoderConfig().appendDefaultContentCharsetToContentTypeIfUndefined(false)
.encodeContentTypeAs("application/octet-stream", ContentType.TEXT)))
You do not need to add Transfer-encoding as REST Assure framework does it for you.
You need urlEncodingEnabled as it automatically encodes, while need encodeContentTypeAs as internally framework using serializer.
This might helped other who may faced similar problem in future.
Upvotes: 0