function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SinowSinow 

Status=Length Required, StatusCode=411

I spend one day and could not fix this problem. when I run these code below in it throw the error: Status=Length Required, StatusCode=411, Please help me to take a look at it. Thanks very very much.

 

the code is:

String endpoint = 'http://www.websequencediagrams.com/index.php?';
String httpMethod = 'POST';
String paramStyle = 'style=earth';
String paramMessage = '&message=test';
HttpRequest request = new HttpRequest();
request.setEndpoint(endpoint + paramStyle + paramMessage);
request.setMethod(httpMethod);
request.setTimeOut(6000);
request.setHeader('Charset', 'UTF-8');
request.setHeader('Content-Length', '-1');
request.setHeader('Content-Type', 'text/plain');
HttpResponse response = new Http().send(request);
if(response.getStatusCode() >= 200 && response.getStatusCode() < 400)
{
system.debug(response.getBody());
}
else
{
system.debug(response.getBody());
} 

the bug is:

<P>
Some aspect of the HTTP Request is invalid.  Possible problems:
<UL>
<LI>Missing or unknown request method
<LI>Missing URL
<LI>Missing HTTP Identifier (HTTP/1.0)
<LI>Request is too large
<LI>Content-Length missing for POST or PUT requests
<LI>Illegal character in hostname; underscores are not allowed
</UL>
SuperfellSuperfell

Remove this line 

request.setHeader('Content-Length', '-1');
SinowSinow

it also throw 411 error when remove this line.

Jia HuJia Hu
try request.setHeader('Content-Length', '512');
Satish PrajapatSatish Prajapat
Hello All,
please refer the below code:
HttpRequest req = new HttpRequest();
req.setEndpoint('Your url which you want to hit.');
req.setMethod('POST');
req.setBody('Body');//When I added this tag than I removed the 'read time out error.'
HttpResponse response = new Http().send(req);

Enjoy My Dost...!!!!