Can we hit a private server URL with HTTP request from Salesforce ?? or the server should always be public.
I have make the Post callout which was written in Rails (hosted on Private server- VPN connected) which will get the Json response. When i tried to execute the code in Salesforce, i got an error 'Server unavailable,status code = 503'.
Below is the Apex class and Response Code
public class CreateSalesOrder {
public static String makePostCallout() {
String responsebody;
JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject();
gen.writeStringField('companyName', '1234');
gen.writeStringField('firstName', 'open');
gen.writeStringField('lastName', 'High');
gen.writeStringField('address1', 'High');
gen.writeEndObject();
String jsonS = gen.getAsString();
// Sending the http body with JSON
String endpoint = 'http://xxx.stage.com/salesforce/api';
HttpRequest req = new HttpRequest();
req.setEndpoint(endpoint);
req.setMethod('POST');
req.setHeader('Content-Type', 'application/json;charset=UTF-8');
req.setHeader('Accept', 'text/html');
req.setbody(jsonS);
System.debug(req);
try {
Http http = new Http();
HTTPResponse response = http.send(req);
System.debug('HTTP Response Code: ' + response.getStatusCode());
System.debug('Response Body: ' + response.getBody());
return response.getBody();
} catch (Exception e) {
System.debug('Callout Error:' + e.getMessage());
return e.getMessage();
}
}
}