Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用restify framework for Node.JS解析/读取多个参数_Node.js_Query String_Request.querystring_Querystringparameter_Restify - Fatal编程技术网

如何使用restify framework for Node.JS解析/读取多个参数

如何使用restify framework for Node.JS解析/读取多个参数,node.js,query-string,request.querystring,querystringparameter,restify,Node.js,Query String,Request.querystring,Querystringparameter,Restify,场景:我们开发人员正试图用Node.JS Restful API替换web服务(用C#.Net编写) 问题:现在我们需要按原样处理传入的请求(我们无法控制它)。因此,以下是传入URL的格式: http://www.website.com/Service.aspx?UID=Trans001&FacebookID=ae67ea324&GetDetailType=FULL 我可以像这样处理URL: http://www.website.com/service/Trans001/ae67ea324/FU

场景:我们开发人员正试图用Node.JS Restful API替换web服务(用C#.Net编写)

问题:现在我们需要按原样处理传入的请求(我们无法控制它)。因此,以下是传入URL的格式:

http://www.website.com/Service.aspx?UID=Trans001&FacebookID=ae67ea324&GetDetailType=FULL

我可以像这样处理URL:

http://www.website.com/service/Trans001/ae67ea324/FULL

我可以从上面的URL解析/读取参数

代码:


问题:如何从格式为
的URL读取多个参数http://www.website.com/Service.aspx?UID=Trans001&FacebookID=ae67ea324

您只需要像这样加载查询解析器插件

server.use(restify.plugins.queryParser());

Simon的答案不再有效,因为restify的queryParser已被移动到restify插件包中。更新的解决方案是

server.use(require('restify-plugins').queryParser());
Restify 5(2017)答案:

从restify 5开始,您现在可以按如下方式设置查询解析器:
server.use(restify.plugins.queryParser())

如果使用此插件,您可以访问
req.query
中解析的参数


有关其他选项和信息,请查看restify文档:

True。这将允许通过req.query.my_param读取查询字符串参数,现在
restify plugins
已被弃用。。。更新后的解决方案是
server.use(restify.plugins.queryParser())
server.use(require('restify-plugins').queryParser());