Skip to content

Set Content-Length in the request headers

Larissa Pereira requested to merge set-content-length into master

Context - By Default, the HttpURLConnection buffers the complete request body in memory before it is transmitted. You can't set the content length; it's done automatically. Therefore, despite setting the "Content-Length" in the HttpRequest headers we saw the following errror

HttpResponse(body={"fault":{"faultstring":"Content-Length is missing","detail":{"errorcode":"messaging.adaptors.http.flow.LengthRequired"}}}, contentType=application/json, responseCode=411, exception=null

Solution - We can use setFixedLengthStreamingMode(long contentLength), when the content length is known in advance.

Edited by Larissa Pereira

Merge request reports