Getting this error randomly

response body length does not match http content-length header.

I am trying to use remote_file resource to download the zip file from my https server.
Sometimes the remote_file resource downloads the file completely and sometimes it fails with the error shown below:-

Error executing action create on resource ‘remote_file[E:\Hotfix\]’

Response body length 24xxxx does not match HTTP Content-Length header 8xxxxx.
This error is most often caused by network issues (proxies, etc) outside of chef-client.

Without making any change anywhere to the cookbook when we run chef-client again we see that it is passed successfully.

As the error message states, this is likely an issue with your network or the configuration of the remote server. The server had told chef that the file was about 800k, but the file that chef got was only about 240k, and therefore was probably incomplete and/or corrupted. If the problem is really intermittent and you just want to work around the issue for now, you could add retries to the remote file resource. If you have access to the logs on the server that hosts the file, that may be a good place to start troubleshooting the issue for a more robust solution.