简体   繁体   English

简单的Meteor HTTP通话超时

[英]Simple Meteor http call timing out

I wish to get some currency prices from a web service which provides them in JSON format. 我希望从以JSON格式提供的Web服务中获取一些货币价格。

Here is the code I am using with the simple example (hello world) - 这是我在简单示例(世界)中使用的代码-

  if (Meteor.isClient) {
    Template.hello.greeting = function () {
     return "Welcome to webserve.";
     };

  Template.hello.events({
    'click input' : function () {
      // template data, if any, is available in 'this'
      if (typeof console !== 'undefined')
        console.log("You pressed the button");
        Meteor.call('getprice');
    }
  });
}

if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup
  });

  Meteor.methods({
  getprice: function() {
    console.log('On the server');
    var url = "http://quotes.instaforex.com/get_quotes.php?m=json&q=AUDUSD";
    //var url ="http://www.google.com";

    HTTP.get(url, function(error, result) {
    if(!error) {
        console.log(result.content);
        }
    else console.log(error);
    }); 
  }
 }); 

}

When I run the app, and click the button in the client, i get a timeout message on the server. 当我运行该应用程序并单击客户端中的按钮时,我在服务器上收到超时消息。 Notice the url - If I copy/paste it in a browser I receive the right json, Cross Domain policy does not apply because the code is on server side. 请注意url-如果在浏览器中复制/粘贴该URL,则会收到正确的json,因此跨域策略不适用,因为该代码位于服务器端。

Any ideas? 有任何想法吗?

复制到新项目中很有帮助,无需更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM