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
Nikhil Khandare 1Nikhil Khandare 1 

Read Time out in HTTP Callout

HI All,

I am trying to connect to the reseful webservice using HTTP callout. However, each time I am getting Read time out exception. Even I set maximum allowed time out ie 120 sec.

Using browser, postman and SoapUI, I am able to connect to the webservice. However, with only apex code, I am facing this issue. Please let me know how can I fix this error. Below is the code.

public class CraiWSCall {

    //This is used to fetch access cookie based token from Crai WS
    
    public String getAuthToken()
    {
        String cookie = '';
        String access_token = '';
        CraiCredentials__c obj = CraiCredentials__c.getValues('TokenEndpoint');
        HttpRequest req = new HttpRequest();  
        req.setMethod('POST');
        req.setEndpoint(obj.Endpoint__c + '?username=test&password=test');
        req.setHeader('Content-type', 'text/plain');
        req.setHeader('Content-length', '27');
        //req.setHeader('Host', 'puntivendita.crai.org');
        // req.setHeader('Proxy-Connection', 'Keep-Alive');
        // req.setTimeout();
        Http httpObj = new Http();
        HTTPResponse res = new HttpResponse();
        res  = httpObj.send(req); 
        System.debug('Error Messeg:' + res.getStatus());
         return cookie;
    }
}
 
Nikhil Khandare 1Nikhil Khandare 1
I figured it out. The issue was with content-length header. I set it to 0 and it worked.