• Sinow
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

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>
  • June 20, 2012
  • Like
  • 0

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>
  • June 20, 2012
  • Like
  • 0