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
Luis MatosLuis Matos 

POST Method error 411

 @Future(callout=true)
     public static void  makePostCallout(String jbody) {
         //STring jbody = json.serialize(accs.Value);
            System.debug('OLHA O BODY:::::' + jbody);
            
            String ep = 'link to endpoint';
            
            HttpClient httpObj = new HttpClient('client and pass here');  // Note two forward slashes between domain and username \\  /
//HttpRequest req = new HttpRequest();
           // Http x = new Http();
            HttpRequest response = new HttpRequest();
               response.setMethod('POST');
            response.setEndpoint(ep);
            
            response.setbody(jbody);
            response.setHeader('Content-Type', 'application/soap+xml;charset=UTF-8');

            response.setHeader('Accept','application/json');
            response.setHeader('Content-Length', '512');
            response.setHeader('Content-Transfer-Encoding','base64');
            response.setHeader('KeepAlive','true');
             response.setCompressed(true);
             
            System.debug('OLHA O BODYAGORA :::::' + response.getBody());
            HttpResponse res2 = httpobj.send(response);
            system.debug('RESPOSTA DO FUTURE::::::::' + res2.getbody());
    } 



This code when trying to post updates to server keeps giving me the error 411 like this :
16:18:13:000 USER_DEBUG <HTML><HEAD><TITLE>Length Required</TITLE>
16:18:13:000 USER_DEBUG <META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
16:18:13:000 USER_DEBUG <BODY><h2>Length Required</h2>
16:18:13:000 USER_DEBUG <hr><p>HTTP Error 411. The request must be chunked or have a content length.</p>
16:18:13:000 USER_DEBUG </BODY></HTML>

Am I doing something wrong???
pconpcon
I would try removing the setCompressed first.  I have found that sometimes this screws with POST requests.
Srinath R 9Srinath R 9
How were you able to resolve this error? I am facing a similar error when making a POST request from Salesforce.