0

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!

2

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 '16 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 at 7:17
0

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();
    req.setEndpoint('https://myapp.com/myapp');
    req.setMethod('GET');
    // Set the content type which you are expecting.
    req.setHeader('content-type','application/json');
0

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

https://help.salesforce.com/articleView?id=000003652&type=1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.