I'm currently facing an issue when trying to send the JSON data request below to a 3rd party system using the "N/https" modules https.post() method.
Upon sending the request, I receive a Response Code of "200" along with the Error Message "Unexpected character encountered while parsing value: S. Path '', line 0, position 0"
Here is my code snippet:
var requestData = {
"terminal": "345678",
"user": "TestUser1234",
"password": "XXXXXX",
"Currency": "USD",
"Total": "25",
"GoodURL": "https://gatewayxx.test.com/sandbox/landingpage",
"Language": "EN"
};
log.debug('Typeof - RequestData: ', typeof requestData);
var headerObj = {};
headerObj['Content-Type'] = 'application/json';
headerObj['Accept'] = 'application/json';
var response = https.post({
url: "https://gatewayxx.test.com",
body: requestData
});
HTTPS POST Responses Message:
{
"type": "http.ClientResponse",
"code": 200,
"headers": {
"Cache-Control": "private",
"Server": "Microsoft-IIS/7.5",
"Content-Length": "152",
"Date": "Fri, 02 Oct 2020 05:44:47 GMT",
"Content-Type": "text/html; charset=utf-8",
"Via": "1.1 mono002"
},
"body": "{\"URL\":\"\",\"ConfirmationKey\":\"\",\"Error\":{\"ErrCode\":599,\"ErrMsg\":\"Unexpected character encountered while parsing value: S. Path '', line 0, position 0.\"}}"
}
After validating my request data in a JSON validator and confirming its type as "object", I am puzzled by the mismatched content-type in the response message which indicated "text/html" rather than JSON data.
If anyone could provide insight into this issue, it would be greatly appreciated.
Thank you for your assistance.