来自heroku的https请求 [英] https request from heroku
问题描述
我试图通过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'],函数(d){
var chunk ='';
d.on('data',function(data){
chunk + = data;
});
d.on 'end',function(){
console.log(chunk);
});
})。on('error',function(e){
console。错误(e);
});
但是在heroku日志中我看到
错误:协议:https:不支持。
那么,我怎样才能得到这些数据呢?我的应用程序在http协议中工作,这是config:
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')));
});
$ b 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'));
});
Node v0.8.9添加了使https生效的功能。 get()接受一个URL。
除非你有一个非常明确的原因,否则在package.json的引擎下使用node:0.10.x。
另请尝试:
`var options = {
host:'api.vk.com',
port:443,
path:'/method/users.get?access_token='+ global ['access_token']
};
https.get('options',function(....`
I am tying to get data from vk.com api via https protocol. like this (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);
});
but in heroku logs I see
Error: Protocol:https: not supported.
So, how can I get this data? My app work in http protocol, this is config:
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'));
});
Node v0.8.9 added the functionality to make https.get() accept a URL.
Unless you have a very specific reason, use "node": "0.10.x" under engines in package.json.
Also try:
`var options = { host: 'api.vk.com', port: 443, path: '/method/users.get?access_token=' + global['access_token'] };
https.get('options', function(....`
这篇关于来自heroku的https请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!