admin管理员组文章数量:1323330
In my node.js app, I want to make an https api call. I am trying with the https
module and it is not working, but then I try with a request
module, and that works.
not work
var options = {
host : 'myserver/platform-api/v1',
port : 80,
path : '/projects?access_token=38472',
method : 'GET',
headers : {
'Accept' : 'application/json'
}
};
var req = https.request(options, function(res) {
res.on('data', function(chunk) {
console.log(chunk);
});
});
req.on('error', function(e) {
console.log(e);
console.log('problem with request:', e.message);
});
req.end();
I get this
problem with request: getaddrinfo ENOTFOUND myserver/platform-api/v1
myserver/platform-api/v1:80
this works
request("https://myserver/platform-api/v1/projects?access_token=38472", function(error, response, body) {
if (error) return console.log(error);
//console.log(error);
//console.log(response);
console.log(body);
});
I can't figure out why it does not work on the first one. Does anyone know why?
Thanks
In my node.js app, I want to make an https api call. I am trying with the https
module and it is not working, but then I try with a request
module, and that works.
not work
var options = {
host : 'myserver/platform-api/v1',
port : 80,
path : '/projects?access_token=38472',
method : 'GET',
headers : {
'Accept' : 'application/json'
}
};
var req = https.request(options, function(res) {
res.on('data', function(chunk) {
console.log(chunk);
});
});
req.on('error', function(e) {
console.log(e);
console.log('problem with request:', e.message);
});
req.end();
I get this
problem with request: getaddrinfo ENOTFOUND myserver/platform-api/v1
myserver/platform-api/v1:80
this works
request("https://myserver/platform-api/v1/projects?access_token=38472", function(error, response, body) {
if (error) return console.log(error);
//console.log(error);
//console.log(response);
console.log(body);
});
I can't figure out why it does not work on the first one. Does anyone know why?
Thanks
Share edited Sep 28, 2017 at 20:25 omega asked Sep 28, 2017 at 20:22 omegaomega 44k90 gold badges285 silver badges522 bronze badges 1- Instead of passing options as a param maybe pass options.path? – Dylan Wright Commented Sep 28, 2017 at 20:25
2 Answers
Reset to default 3EDIT Switched to port 443 as well.
Your host
seemed to include part of the path? Try this instead (left just the host in host
and moved the path to path
):
var options = {
host : 'myserver',
port : 443,
path : '/platform-api/v1/projects?access_token=38472',
method : 'GET',
headers : {
'Accept' : 'application/json'
}
};
Also, you're hitting port 80, which is usually not the HTTPS port.
本文标签: javascriptHttps request not working in nodejsStack Overflow
版权声明:本文标题:javascript - Https request not working in node.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742139280a2422509.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论