创建一个返回JSON正文的https OPTIONS请求

时间:2015-11-24 09:46:29

标签: javascript json node.js rest https

如何使用node.js向现有REST端点发出https OPTIONS请求?

当我使用带有OPTIONS请求方法的postman时,我会返回所有现有端点的JSON主体。

我关注了node.js文档,这就是我正在做的事情 -

var options = {
    hostname: host,
    port: 443,
    path: urlPar,
    method: 'OPTIONS'
};

var req = https.request(options, function(res){
    console.log("statusCode: ", res.statusCode);
    console.log("headers: ", res.headers);

    res.on('data', function(d) {
        console.log("returned data", d);
    });
});

req.end();

req.on('error', function(e){
    console.error("error thrown", e);
});

但我收到了请求的错误 -

{ [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }

还有其他方法可以做到这一点吗?

0 个答案:

没有答案