我试图调用方法,在这里,我做一个http get,如果结果是确定的,我返回它并在我的mongodb基础上跟踪它,如果它返回给我一个错误,我也想跟踪它。
不幸的是,它不起作用!我读过关于堆栈溢出的文章,但是只有一些老问题。
你有什么解决办法吗?
客户:
Meteor.call('get',function(err, response) {
console.log(err+" ee"+response);
});服务器:
var header = 'xxxxxxxx';
Meteor.startup(function () {
Meteor.methods({
get : function(){
console.log("call");
var url = 'http://xxxxxxxxxx';
this.unblock();
Meteor.http.get(url, function(err,res){
if(!err){
//tracking
return res;
}else{
//tracking
return err;
}
});
}
});
});发布于 2014-05-19 09:23:35
在服务器上,您可以在没有回调的情况下调用HTTP.get来执行“同步”HTTP调用。您需要在命令行执行meteor add http,以便将HTTP添加到项目中。
Meteor.methods({
get: function(){
console.log("call");
var url = 'http://xxxxxxxxxx';
this.unblock();
try {
var res = HTTP.get(url);
// tracking
return res;
} catch (err) {
// tracking
return err; // or throw new Meteor.Error(...)
}
}
});https://stackoverflow.com/questions/23733983
复制相似问题