After upgrading to Springboot 3.2.0 from Springboot 3.1.5, custom RestTemplate is not setting the Content-Length header for requests.
The custom RestTemplate created was created with Apache HttpClient5: 5.2.3. The HttpClient is constructed to ignore hostname verification and SSL verification.
Comment From: scottfrederick
Thanks for getting in touch. It is difficult for us to know what is going on with the limited information you've provided. If you would like us to spend some time investigating, please provide a complete minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it and attaching it to this issue.
Comment From: bclozel
This is called out in the Spring Framework upgrade guide at the end of the web section here.
This was done for memory optimization but you can reinstate this behavior.
Edit: also see https://github.com/spring-projects/spring-framework/issues/31854#issuecomment-1858817976
Comment From: hpeimer
Thank you @bclozel
Comment From: dvag-erich-achilles
Hello, upgrading spring-boot-starter-parent from 3.2.4 to 3.2.5 we got the same error again. As recommended whe still use BufferingClientHttpRequestFactory. Any ideas ?
Comment From: bclozel
@dvag-erich-achilles is this for 0 length request bodies? If that's the case, see spring-projects/spring-framework#32678
Comment From: dvag-erich-achilles
@bclozel yes it is for 0 length request bodies, thank you for your hint.
Comment From: rajukosna
We got same error insufficient data written : I/O error on POST request for "http:// when we migrated springboot 2.x to 3.3 version, ut I did nt get solution ... please can any one help to give solution... Here I am using the RestTemplate to API calls, so while calling API call got this error.
Comment From: rajukosna
I used the this picemof code headers.add(HEADER_NAME, getFullContextInJson()); headers.add("Content-Length", MAX_TRANSFER_SIZE); HttpEntity<?> httpEntity = new HttpEntity<>(body, headers); responseEntity = restTemplate.exchange(UriComponentsBuilder.fromHttpUrl(url).build(true).toUriString(), httpMethod, httpEntity, ResponseDTO.class);
Comment From: bclozel
Can you share a minimal sample application that we can git clone or unzip then run? Once you can share this sample application please open a new issue here: https://github.com/spring-projects/spring-framework/issues
If you cannot reproduce the problem with a minimal application then please ask a question on StackOverflow.