NetSuite https.post() 方法响应给出错误 "Unexpected character encountered while parsing value: S. Path '', line 0, position 0"
NetSuite https.post() method response is giving Error "Unexpected character encountered while parsing value: S. Path '', line 0, position 0"
我正在尝试使用“N/https”模块 https.post() 方法向第三方系统发送以下 JSON 数据请求。
我得到的响应代码为“200”,错误消息为 “解析值时遇到意外字符:S.路径”,第 0 行,位置 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 数据时犯了什么错误,谁能帮助我理解这个问题。
非常感谢。
您似乎为您的请求创建了一个 header,但最终您没有在 post 请求中使用它。有什么特别的原因吗?
当您收到 200 响应代码时,这意味着 POST 请求已正确通过。然而,无论你试图得到什么,都是窃听。更具体地说,您会收到 599 错误代码,这通常用于大多数代理的超时。所以这个问题可能不是来自你,而是来自你正在使用的API
您将 JSON 数据指定为 headers 中的 Content-Type,但您在 [=] 中传递了 JavaScript Object 17=]。您需要将 object 字符串化为 JSON 字符串:
var response = https.post({
url: "https://gatewayxx.test.com",
body: JSON.stringify(requestData)
});
此外,正如 bluehank 所指出的,您没有在请求中发送 headers - 您可能是指:
var response = https.post({
url: "https://gatewayxx.test.com",
body: JSON.stringify(requestData),
headers: headerObj
});
我正在尝试使用“N/https”模块 https.post() 方法向第三方系统发送以下 JSON 数据请求。
我得到的响应代码为“200”,错误消息为 “解析值时遇到意外字符:S.路径”,第 0 行,位置 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 数据时犯了什么错误,谁能帮助我理解这个问题。
非常感谢。
您似乎为您的请求创建了一个 header,但最终您没有在 post 请求中使用它。有什么特别的原因吗?
当您收到 200 响应代码时,这意味着 POST 请求已正确通过。然而,无论你试图得到什么,都是窃听。更具体地说,您会收到 599 错误代码,这通常用于大多数代理的超时。所以这个问题可能不是来自你,而是来自你正在使用的API
您将 JSON 数据指定为 headers 中的 Content-Type,但您在 [=] 中传递了 JavaScript Object 17=]。您需要将 object 字符串化为 JSON 字符串:
var response = https.post({
url: "https://gatewayxx.test.com",
body: JSON.stringify(requestData)
});
此外,正如 bluehank 所指出的,您没有在请求中发送 headers - 您可能是指:
var response = https.post({
url: "https://gatewayxx.test.com",
body: JSON.stringify(requestData),
headers: headerObj
});