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.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!

3 Answers 3


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.

  • This answer looks fine to me.
    – martin
    Jul 26, 2016 at 2:04
  • Even when I whitelist all the IPs, I still get one of the batch apex records to be "common.apex.runtime.impl.ExecutionException: Read timed out"
    – compski
    Mar 12, 2019 at 7:17

You need to set the content type header as well. Depending on the response returned. Content type can be JSON, XL etc.

    HttpRequest req = new HttpRequest();
    // Set the content type which you are expecting.

Had the same Issue, Put all de addresses of the URL in the whitelist of the server to callout and it works.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .