[SalesForce] Read timed out/Unexpected end of file from server Error

I have a third-party application running on Heroku. I am sending a GET request to this application, expecting a 200 OK from it. Here's my code for this:

    HttpRequest req = new HttpRequest();
    req.setEndpoint('https://myapp.com/myapp');
    req.setMethod('GET');
    req.setTimeout(2 * 60 * 1000);


    Http http = new Http();
    HttpResponse res = http.send(req);
    System.debug('The body is: ' + res.getBody());

However, I get "Read timed out" error if there's is no setTimeout in the code and "Unexpected end of file from server" error if there's setTimeout in the code.

The very code works fine if I change the url to some other app, say Google. I am unable to understand where the problem is. My app works perfectly fine from the browser or from POSTMAN. Not sure why salesforce platform is unable to connect. Any help would be highly appreciated!

Best Answer

Thanks for answering. The problem is with the firewall settings. My app's firewall has been blocking the traffic from external IPs. Once we added the IP to whitelist, everything is fine.

Related Topic