Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.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
Node.js ExpressJS I can';t获取以';http或https';_Node.js_Express_Parameters_Routes - Fatal编程技术网

Node.js ExpressJS I can';t获取以';http或https';

Node.js ExpressJS I can';t获取以';http或https';,node.js,express,parameters,routes,Node.js,Express,Parameters,Routes,我希望能够从我的URL中获取一个参数,该参数实际上是一个URL,例如: http://mywebsite.com/new/http://www.url.com 它可以很好地处理任何字符串,但当我将URL作为param(以http开头的字符串)传递时,会出现以下错误: Cannot GET /new/http://www.url.com 这是我的密码: app.param('url', function(req, res, next, url) { if (isURL(url)) {

我希望能够从我的URL中获取一个参数,该参数实际上是一个URL,例如:

http://mywebsite.com/new/http://www.url.com
它可以很好地处理任何字符串,但当我将URL作为param(以http开头的字符串)传递时,会出现以下错误:

Cannot GET /new/http://www.url.com
这是我的密码:

app.param('url', function(req, res, next, url) {
    if (isURL(url)) {
        req.url = url;
    } else {
        res.end('Invalid URL');
    }

    next();
});

app.get('/new/:url', function(req, res) {
    res.end(req.url);
});

var port = process.env.PORT || 8080;

app.listen(port, function() {
    console.log('Listening on port ' + port + '...');
});

非常感谢。

ExpressJS自动解析url并通过“/”将其划分为多个部分,您可以执行以下操作

app.get('/new/:url*', function(req, res) {

    var urlInTheParam = req.params['url'] + req.params[0];
    //Then you can do you things with the url in the params

});

ExpressJS自动解析url并通过“/”将其划分为多个段,您可以执行以下操作

app.get('/new/:url*', function(req, res) {

    var urlInTheParam = req.params['url'] + req.params[0];
    //Then you can do you things with the url in the params

});

您是否尝试过对参数进行URL编码?例如,您是否尝试过对参数进行URL编码?例如