
We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.
When invoking an HTTP POST callout from Salesforce Apex, a 'Content-Length is missing' error may appear in the debug log. This error is observed when making HTTP POST requests using the Apex HttpRequest class.
Example scenario: An HTTP POST callout is executed in Apex using the HttpRequest class. The request sets an endpoint, method, Authorization header, and Content-Type header. However, the Content-Length header is not set.
The error code messaging.adaptors.http.flow.LengthRequired indicates that the HTTP POST request is missing the required Content-Length header.
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://xxxx');
req.setMethod('POST');
.......
........
req.setHeader('Authorization', authorizationHeader);
req.setHeader('Content-Type','application/json');
HttpResponse res = h.send(req);
When the request is sent, the following error is returned by the server:
{"fault":{"faultstring":"Content-Length is missing","detail":{"errorcode":"messaging.adaptors.http.flow.LengthRequired"}}}
The error code messaging.adaptors.http.flow.LengthRequired indicates that the HTTP POST request is missing the required Content-Length header.
The error occurs because HTTP POST requests require a Content-Length header to indicate the size of the request body.
If the request body is empty, set the Content-Length value to 0 using the following Apex method on your HttpRequest object:req.setHeader('Content-Length', '0');
If the request body has content, calculate the byte length of the body string and pass it as the Content-Length value.
POST requests by the HTTP specification require the Content-Length header when sending a body. If the body is absent or the header is missing, many servers will reject the request with a 411 Length Required error — which is the error code shown above (LengthRequired).
000387575