I am making a HTTP POST callout from Salesforce. I am getting a HTTP 200 response code from the remote server but I am not getting the response body in the response. However, when I am using the same request body to send the data from postman, I am getting the response body.
Here's the Salesforce code I am using:
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setEndpoint('https://ZXXXXXXXX/api/ZXXXXXXXX');
String username = 'ZXXXXXXXX';
String password = 'XXXXXXXXXXXXXXX';
Blob headerValue = Blob.valueOf(username + ':' + password);
String authorizationHeader = 'Basic ' +
EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);
req.setHeader('Content-Type', 'application/json');
req.setBody(JSON.serialize(lstOfObjectIWantToSend));
System.debug('json serialized object:
'+JSON.serialize(lstOfObjectIWantToSend));
HttpResponse res = new Http().send(req);
System.debug('Response from Server in Salesforce: '+res);
I am using the reference code depicted here: How to make a post request to some other server from apex controller
Am I doing something wrong here?
First Edit:
In the logs, I am printing the entire response object, this is what I see:
USER_DEBUG [50]|DEBUG|Response from Dynamics in Salesforce: System.HttpResponse[Status=OK, StatusCode=200]
Best Answer
I got the response when I used res.getBodyAsBlob().toString();