【发布时间】:2021-01-17 21:31:47
【问题描述】:
我正在尝试使用“N/https”模块 https.post() 方法将以下 JSON 数据请求发送到第 3 方系统。
我得到的响应代码为“200”,错误消息“解析值时遇到意外字符:S. Path '', line 0, position 0”
请参考我下面给出的代码
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 = new Array();
headerObj['Content-Type'] = 'application/json';
headerObj['Accept'] = 'application/json';
var response = https.post({
url: "https://gatewayxx.test.com",
body: requestData
});
HTTPS POST 响应消息:
{
"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.\"}}"
}
我在 JSON 验证器中检查了我的请求数据,其中没有错误。同样在代码中,我使用 typeof 属性对其进行了验证。它也将其显示为“对象”。
此外,如果您注意到响应消息,它会将响应“Content-Type”作为“text/html”而不是 JSON 数据给出。
我不确定我在发送 JSON 数据时犯了什么错误,谁能帮我理解这个问题。
非常感谢。
【问题讨论】:
标签: javascript json https netsuite suitescript2.0