【发布时间】:2015-07-24 12:27:12
【问题描述】:
下面是 nodejs 应用程序请求到我的另一个 https 服务器
var https = require('https');
jsonObject = JSON.stringify({"arg1":"4","arg2":"True"});
// prepare the header
var postheaders = {
'Content-Type' : 'application/json',
'Content-Length' : Buffer.byteLength(jsonObject, 'utf8')
};
// the post options
var optionspost = {
host : 'https://www.example.com/',
path : '/my/path/?arg1=4&arg2=True',
method : 'POST',
headers : postheaders
};
var reqPost = https.request(optionspost, function(res) {
console.log("statusCode: ", res.statusCode);
res.on('data', function(d) {
console.info('POST result:\n');
process.stdout.write(d);
console.info('\n\nPOST completed');
});
});
reqPost.write(jsonObject);
reqPost.end();
reqPost.on('error', function(e) {
console.error(e);
});
我总是遇到以下错误,任何人都可以说出我哪里出错了
{ [错误:getaddrinfo ENOTFOUND https://www.example.com/] 代码:'ENOTFOUND', 错误号:'ENOTFOUND', 系统调用:'getaddrinfo', 主机名:'https://www.example.com/'}
【问题讨论】: