I am trying to pass a json data to an external URL. With a basic knowledge, I have added them to remote site settings. The sample URL is http://xyz-xyz.sap.xx.com:50000/xyz/xyz
. I have created an apex class and tried the callout from Apex.
But I'm getting this error:
"Status=Service Unavailable, StatusCode=503"
But the SAP person tried this from SOAPUI with basic authentication by suppling the username and password and got the status as 202. Could someone please tell me where I'm making the mistake. From Salesforce we were not able to hit the SAP endpoint itself.
public static HttpResponse makePostCallout() {
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('http://xyz-xyz.sap.xx.com:50000/xyz/xyz');
system.debug('endPoint+++++'+request.getEndpoint());
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
request.setBody('{"Id" :"123", "name":"mighty moose"}');
HttpResponse response = http.send(request);
// Parse the JSON response
if (response.getStatusCode() != 201) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
} else {
System.debug(response.getBody());
}
return response;
}