[SalesForce] How to call the external web service from apex call out

Please find below the code I am using:

Http http = new Http();
HttpRequest request = new HttpRequest(); 
String url='http://abc:8090/part/abc/abc/';
request.setEndpoint(url);
request.setMethod('GET');
HttpResponse response = http.send(request);
System.debug('Response:'+response);

I am able to access the url in the browser and I have added the base url in the Remote site settings too. But the above code does not call the web service. The reponse I get is

Response:System.HttpResponse[Status=Service Unavailable,
StatusCode=503]

And when I change the url to 'https://th-apex-http-callout.herokuapp.com/animals' It works perfectly well.

Could anyone please help me if there is anything wrong with the url?

Best Answer

Hi @NewSalesforceDev,

Your organization/Customer white-listed you network IP address. Hence it is accessible when you hit the URL(http://abc:8090/part/abc/abc/) in your browser (from your organization or from your VPN connection).

This URL is not accessible by other public IP's (including Salesforce IP's). You can test this by hitting the same URL from your home network(without connecting to your customer network. This URL will not be accessible).

Solution: Ask your Customer Network team to whitlist the Salesforce IP's. Provide the Salesforce Ip list to your Customer Network team from the below URL.

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

Thanks, Syed