简体   繁体   中英

Meteor's HTTP 'GET' request does not get XML file

I am working on a research project at my university using the WeatherHawk 916 Wireless Weather Station and using the IP Module connected to it so that it makes the weather data available on campus' network.

To access the data, you have to type an IP Address in a web browser and the data appears as follows: Weather Station Website . The IP Module's server also offers the data as XML (which is what I am interested in so that I can get it using Meteor's HTTP 'GET' and parse it). If you click on "Get Public Table XML", this page appears: XML Data .

If I do the Meteor 'GET' HTTP request on the main page, which is just '10.181.160.100', I get the whole HTML page back with no problem, which is good. However, if I try to get the XML from '10.181.160.100/get_public_tbl.cgi?A=1', i get the following error:

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)

I was discussing the issue with my faculty advisor and he had the same problem in Java using HTTP Request. He used Firefox's 'Web Developer' tool and saw the Network incoming and outgoing files. The main website returned a status code of 200, which is good, but the one with the XML did not have a header file apparently (so no status code). We said that maybe this was the problem. So instead, he tried using a Socket and then he used a 'GET' request on a PrintWriter using the Socket's InputStream and it worked perfectly. He got the XML back. Now, I don't know if Socket programming is available in Meteor (server-side) / JavaScript.

Here is the code I have for the HTTP call (and fails), which is synchronous for now:

'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);
    }
}

If I just do 10.181.160.100/ instead of the current link, it returns back data and it prints to the console (data is undefined if you try to print with the link of the XML file).

So I guess the question is if there is any way we can do Socket Programming to deal with this or anyone knows any other Meteor package that I can add and maybe help me deal with this problem. Thanks in advance.

Update 1

Here's the cURL information gotten from Chrome Network feature as requested:

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

Also, I surrounded the code in a try and catch and I got the following error:

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)

Answer changed. See history for previous (incorrect) attempt.

Try changing your code to do this...

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);
        }   
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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