我正在使用WeatherHawk 916无线气象站并使用连接到它的IP模块在我的大学开展研究项目,以便在校园内提供天气数据。网络。
要访问数据,您必须在Web浏览器中键入IP地址,数据显示如下:Weather Station Website。 IP模块的服务器还提供XML数据(这是我感兴趣的,这样我就可以使用Meteor的HTTP' GET'并解析它)。如果您点击"获取公共表格XML",则会显示此页面:XML Data。
如果我做流星' GET'主页上的HTTP请求,只是' 10.181.160.100',我没有任何问题得到整个HTML页面,这很好。但是,如果我尝试从' 10.181.160.100/get_public_tbl.cgi?A = 1'获取XML,我会收到以下错误:
I20160620-17:41:11.662(-4)? Exception while invoking method 'xmlDemo' Error: Parse Error
I20160620-17:41:11.833(-4)? at Object.Future.wait (/Users/melkisespinal/.meteor/packages/meteor- tool/.1.3.3_1.ajs0iq++os.osx.x86_64+web.browser+web.cordova/mt- os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:449:15)
I20160620-17:41:11.834(-4)? at Object.call (packages/meteor/helpers.js:119:1)
I20160620-17:41:11.834(-4)? at [object Object].xmlDemo (imports/api/main.js:6:21)
I20160620-17:41:11.834(-4)? at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1704:12)
I20160620-17:41:11.834(-4)? at packages/ddp-server/livedata_server.js:711:19
I20160620-17:41:11.835(-4)? at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20160620-17:41:11.835(-4)? at packages/ddp-server/livedata_server.js:709:40
I20160620-17:41:11.835(-4)? at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20160620-17:41:11.835(-4)? at packages/ddp-server/livedata_server.js:707:46
I20160620-17:41:11.836(-4)? at tryCallTwo (/Users/melkisespinal/.meteor/packages/promise/.0.7.2.71gs7j++os+web.browser+web.cordova/npm/node_modules/promise/lib/core.js:45:5)
I20160620-17:41:11.836(-4)? - - - - -
I20160620-17:41:11.836(-4)? at Socket.socketOnData (http.js:1639:20)
I20160620-17:41:11.837(-4)? at TCP.onread (net.js:528:27)
我正与我的指导老师讨论这个问题,他在使用HTTP请求的Java中遇到了同样的问题。他使用了Firefox的网络开发人员和#39;工具,并看到网络传入和传出文件。主网站返回的状态代码为200,这很好,但是带有XML的那个显然没有头文件(因此没有状态代码)。我们说也许这就是问题所在。所以相反,他尝试使用Socket,然后他使用了一个' GET'使用Socket的InputStream请求PrintWriter,它完美地工作。他得到了XML。现在,我不知道Socket编程是否可用于Meteor(服务器端)/ JavaScript。
以下是我对HTTP调用(和失败)的代码,现在是同步的:
'xmlDemo':function(){
var result = HTTP.call('GET', 'http://10.181.160.100/get_public_tbl.cgi?A=1',
{});
if(result.statusCode == 200){
return result.content;
}
else{
console.log("Response issue: ", result.statusCode);
throw new Meteor.Error(result.statusCode, result.error);
}
}
如果我只是执行10.181.160.100 /而不是当前链接,它会返回数据并将其打印到控制台(如果您尝试使用XML文件的链接进行打印,则数据未定义)。
所以我想问题是,如果有任何方法我们可以做套接字编程来处理这个或任何人都知道我可以添加的任何其他Meteor包,也许可以帮助我解决这个问题。提前谢谢。
更新1
以下是根据要求从Chrome网络功能获取的cURL信息:
curl http://10.181.160.100/get_public_tbl.cgi?A=1'
-H 'Accept-Encoding: gzip, deflate, sdch'
-H 'Accept-Language: en-US,en;q=0.8,es;q=0.6'
-H 'Upgrade-Insecure-Requests: 1'
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
-H 'Cache-Control: max-age=0'
-H 'Connection: keep-alive'
--compressed
另外,我在try和catch中包围了代码,我收到了以下错误:
TypeError: Cannot read property 'statusCode' of undefined
I20160622-20:57:38.918(-4)? at [object Object].xmlDemo (imports/api/main.js:27:6)
I20160622-20:57:38.918(-4)? at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1704:12)
I20160622-20:57:38.918(-4)? at packages/ddp-server/livedata_server.js:711:19
I20160622-20:57:38.919(-4)? at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20160622-20:57:38.919(-4)? at packages/ddp-server/livedata_server.js:709:40
I20160622-20:57:38.919(-4)? at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20160622-20:57:38.919(-4)? at packages/ddp-server/livedata_server.js:707:46
I20160622-20:57:38.920(-4)? at tryCallTwo (/Users/melkisespinal/.meteor/packages/promise/.0.7.2.71gs7j++os+web.browser+web.cordova/npm/node_modules/promise/lib/core.js:45:5)
I20160622-20:57:38.920(-4)? at doResolve (/Users/melkisespinal/.meteor/packages/promise/.0.7.2.71gs7j++os+web.browser+web.cordova/npm/node_modules/promise/lib/core.js:200:13)
I20160622-20:57:38.920(-4)? at new Promise (/Users/melkisespinal/.meteor/packages/promise/.0.7.2.71gs7j++os+web.browser+web.cordova/npm/node_modules/promise/lib/core.js:66:3)
答案 0 :(得分:0)
答案已更改。查看先前(不正确)尝试的历史记录。
尝试更改代码以执行此操作...
var result = HTTP.call(
'GET',
'http://10.181.160.100/get_public_tbl.cgi',
{'query': '?A=1'},
function(error, result) {
if(error) {
// Failed hideously
} else {
// Got a response
if(result.statusCode == 200){
// Was OK
return result.content;
} else {
// Was something other than a 200 OK
console.log("Response issue: ", result.statusCode);
throw new Meteor.Error(result.statusCode, result.error);
}
}
});