我想通过https协议从vk.com api获取数据。像这样(api vk docs):
var https = require('https');
https.get('https://api.vk.com/method/users.get?access_token=' + global['access_token'], function (d) {
var chunk = '';
d.on('data', function (data) {
chunk += data;
});
d.on('end', function () {
console.log(chunk);
});
}).on('error', function (e) {
console.error(e);
});
但是在heroku日志中我看到了
Error: Protocol:https: not supported.
那么,我怎样才能获得这些数据?我的应用程序在http协议中工作,这是配置:
var express = require('express'),
routes = require('./routes');
var app = express();
app.configure(function () {
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
app.configure('development', function () {
app.use(express.errorHandler());
});
app.get('/', routes.index);
http.createServer(app).listen(app.get('port'), function () {
console.log("Express server listening on port " + app.get('port'));
});
答案 0 :(得分:0)
Node v0.8.9添加了使https.get()接受URL的功能。
除非您有特殊原因,否则请使用" node":" 0.10.x"在package.json中的引擎下。
还可以尝试:
`var options = { 主持人:' api.vk.com', 港口:443, 路径:' /method/users.get?access_token =' + global [' access_token'] };
https.get(' options',function(....`