+ Start a Discussion
ShaTShaT 

Status=Length Required, StatusCode=411

Hi All,
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.
Http h = new Http();
       
        HttpRequest req = new HttpRequest();
        req.setEndpoint('https://www.google.com/user/?email=abc@gmail.com');
        req.setMethod('POST');
        req.setCompressed(true);
        req.setHeader('key', '1212113232');
        req.setHeader('Content-Type','text/xml');
       // req.setHeader('Content-Length', '1');// tired it out with diffrent values but still getting error
       
     
System.debug('----------------req-'+req);
        HttpResponse res = h.send(req);
        System.debug(res.getBody());

Result -
HTML><HEAD><TITLE>Length Required</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Length Required</h2>
<hr><p>HTTP Error 411. The request must be chunked or have a content length.</p>
</BODY></HTML>

Thanks
Shail
Best Answer chosen by ShaT
ShaTShaT
Hi Guys,

Thanks for your response.
I am able to solve th issue. I need to use GET method instead of POST. Than i dont need to give Content-Length.

All Answers

Vinit_KumarVinit_Kumar
Can you try with this value in your code :-

req.setHeader('Content-Length', '4096');
ShaTShaT
Hi Vinit,

I am getting read time out error.
When i comment it , than its is giving the length error and when i give the length as you have mentioned its gives 

05:10:48.711 (10711270549)|FATAL_ERROR|System.CalloutException: Read timed out

Class.RESTClient.CallingGetMethod: line 39, column 1
AnonymousBlock: line 1, column 1

Thanks
ShaT
Vamsi KrishnaVamsi Krishna
you can use http://www.hurl.it/ to quickly test your http request ..
ShaTShaT
Its is working fine there i am getting response in XML , But when i try with it from Salesforce its giving the above error.
Vinit_KumarVinit_Kumar
It seems you that the end-point is not responding timely.Salesforce expects a response within 120 seconds else it would throw time-out exception.

Can you try sending the request to requestb.in and see if Content Length is getting associated to header or not.If it is,then it's an issue with the end-point I assume.

Hope this helps !!
ShaTShaT
Hi Guys,

Thanks for your response.
I am able to solve th issue. I need to use GET method instead of POST. Than i dont need to give Content-Length.
This was selected as the best answer