public static void adjustNoChunkedEncoding ( ClientRequest request , String requestBody ) { String fixedLengthString = request . getRequestHeaders ( ) . getFirst ( Headers . CONTENT_LENGTH ) ; String transferEncodingString = request . getRequestHeaders ( ) . getLast ( Headers . TRANSFER_ENCODING ) ; if ( transferEncodingString != null ) { request . getRequestHeaders ( ) . remove ( Headers . TRANSFER_ENCODING ) ; } //if already specify a content-length, should use what they provided if ( fixedLengthString != null && Long . parseLong ( fixedLengthString ) > 0 ) { return ; } if ( ! StringUtils . isEmpty ( requestBody ) ) { long contentLength = requestBody . getBytes ( UTF_8 ) . length ; request . getRequestHeaders ( ) . put ( Headers . CONTENT_LENGTH , contentLength ) ; } }
this method is to support sending a server which doesn t support chunked transfer encoding .