Print this page

HTTP Callout fails with Content-Length is missing error

Knowledge Article Number 000220245
Description While invoking a HTTP callout the following error is observed:
Content-Length is missing
For example if the HTTP callout code is executed in Apex Anonymous Execute the below error is seen the debug log:

Http h = new Http();
HttpRequest req = new HttpRequest();

req.setHeader('Authorization', authorizationHeader);
HttpResponse res = h.send(req);


{"fault":{"faultstring":"Content-Length is missing","detail":{"errorcode":"messaging.adaptors.http.flow.LengthRequired"}}}
Resolution The content length header is missing . It size of the entity body is known add it in the header.
If the body is not present you can specify the length as 0.
req.setHeader('Content-Length', '0'); 

promote demote