MCS/nodejs 中的 URI 参数验证
URI Parameter validation in MCS/nodejs
需要您的帮助来解决问题。我正在 MCS 中编写自定义 API,方法类型为“GET
”,将参数与 URI 一起传递。
service.get('/mobile/custom/****/deviceVersion/:deviceType',function(req,res){
var reqParams = req.params;
var finalResponse;
var params='/'+reqParams.deviceType;
console.info("Request Params>"+params);
if(reqParams.deviceType=='{}'){ // ***Here is my problem***
finalResponse = jbuilder.encode(function (json) {
json.set('Response', function (json) {
json.set('responseCode', '400');
json.set('responseMessage', 'Malformed request query');
});
});
res.status(400).send(finalResponse);
res.end();
}else{
//console.info("In Else and length=>"+reqParams.deviceType+"//"+reqParams.deviceType.length);
//var params='/'+reqParams.deviceType;
var connector='/deviceVersion';
commonHandler.CommonHandlerGetMethodFunction(req,res,connector,params);
}
});
在我的例子中,我必须检查参数 deviceType
是否为空。
我试过以下方法
1. if(reqParams.deviceType=='{}'){}
2. if(JSON.Stringify(reqParams.deviceType)=='{}'){}
3. if(JSON.Stringify(reqParams.deviceType).length==0){}
谁能告诉我验证 null 的正确方法?
提前致谢
已更新
我在将 deviceType
作为 null 传递时遇到的错误是
{
"type": "w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.1",
"status": 404,
"title": "API not found",
"detail": "We cannot find the API ******/1.0 for the provided URL path /deviceVersion/. Verify your request parameters and try again.",
"o:ecid": "005Hp2YhoPF3j4C_nDs1yZ000Uba00001w, 0:3",
"o:errorCode": "MOBILE-57945",
"o:errorPath": "/mobile/custom/******/deviceVersion/"
}
MCS 自定义 Api 中给出的端点是 /deviceVersion/{deviceType}
if (!req.params.deviceType)
应该可以。
此问题已交叉发布到 Oracle OTN MCS 论坛并在那里得到回答:https://community.oracle.com/thread/4012301
需要您的帮助来解决问题。我正在 MCS 中编写自定义 API,方法类型为“GET
”,将参数与 URI 一起传递。
service.get('/mobile/custom/****/deviceVersion/:deviceType',function(req,res){
var reqParams = req.params;
var finalResponse;
var params='/'+reqParams.deviceType;
console.info("Request Params>"+params);
if(reqParams.deviceType=='{}'){ // ***Here is my problem***
finalResponse = jbuilder.encode(function (json) {
json.set('Response', function (json) {
json.set('responseCode', '400');
json.set('responseMessage', 'Malformed request query');
});
});
res.status(400).send(finalResponse);
res.end();
}else{
//console.info("In Else and length=>"+reqParams.deviceType+"//"+reqParams.deviceType.length);
//var params='/'+reqParams.deviceType;
var connector='/deviceVersion';
commonHandler.CommonHandlerGetMethodFunction(req,res,connector,params);
}
});
在我的例子中,我必须检查参数 deviceType
是否为空。
我试过以下方法
1. if(reqParams.deviceType=='{}'){}
2. if(JSON.Stringify(reqParams.deviceType)=='{}'){}
3. if(JSON.Stringify(reqParams.deviceType).length==0){}
谁能告诉我验证 null 的正确方法? 提前致谢
已更新
我在将 deviceType
作为 null 传递时遇到的错误是
{
"type": "w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.1",
"status": 404,
"title": "API not found",
"detail": "We cannot find the API ******/1.0 for the provided URL path /deviceVersion/. Verify your request parameters and try again.",
"o:ecid": "005Hp2YhoPF3j4C_nDs1yZ000Uba00001w, 0:3",
"o:errorCode": "MOBILE-57945",
"o:errorPath": "/mobile/custom/******/deviceVersion/"
}
MCS 自定义 Api 中给出的端点是 /deviceVersion/{deviceType}
if (!req.params.deviceType)
应该可以。
此问题已交叉发布到 Oracle OTN MCS 论坛并在那里得到回答:https://community.oracle.com/thread/4012301