3

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.

DebbieB
  • 31
  • 3
  • Could you please provide a runnable example that shows the problem? Probably Apache sets this header on its own under the hood. List the headers and verify what's going on. – Opal Nov 13 '15 at 17:15
  • I found exactly same problem with rest assured. It works fine by using curl. – Nikhil Oct 03 '17 at 16:32

1 Answers1

0

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.

Nikhil
  • 570
  • 5
  • 12