anoop
anoop

Reputation: 539

Not getting result data using meteor http package

I am trying to retrieve data from a server by making an api call using the Meteor http package. I have written the api call inside a method on the server side. On the client, I am doing Meteor.call() to the method on server. The issue is, am not getting the desired JSON data in meteor, whereas when testing the URL in browser am getting the data.

I have checked on other posts in stack, but they didn't workout. Please help me out why result is not getting properly.

 // on server

    'get_list' : function () {

        var url = "http://10.10.2.48/api/content?type=apartment"; //this is a dummy url due to security reasons.

        Meteor.http.get(url,function(error, result){
            console.log(result);
            return result;
        });
    }

I am getting 406 error with the 'GET' call. Below is the result of it.

{ statusCode: 406,
    content: '',
    headers: 
    { 
        date: 'Wed, 26 Mar 2014 06:50:53 GMT',
        server: 'Apache/2.2.22 (Debian)',
        'x-powered-by': 'PHP/5.4.4-14+deb7u7',
        expires: 'Sun, 19 Nov 1978 05:00:00 GMT',
       'last-modified': 'Wed, 26 Mar 2014 06:50:53 +0000',
       'cache-control': 'no-cache, must-revalidate, post-check=0, pre-check=0',
       etag: '"1395816653"',
       vary: 'Accept,Accept-Encoding',
       'content-length': '0',
       'keep-alive': 'timeout=5, max=100',
       'connection: 'Keep-Alive',
       'content-type': 'text/html' 
    },
    data: null 
}

I have also tried 'POST' call but getting 404 error. Below is the result of it.

 { statusCode: 404,
        content: '',
        headers: 
        { 
            date: 'Wed, 26 Mar 2014 06:50:53 GMT',
            server: 'Apache/2.2.22 (Debian)',
            'x-powered-by': 'PHP/5.4.4-14+deb7u7',
            expires: 'Sun, 19 Nov 1978 05:00:00 GMT',
           'last-modified': 'Wed, 26 Mar 2014 06:50:53 +0000',
           'cache-control': 'no-cache, must-revalidate, post-check=0, pre-check=0',
           etag: '"1395816653"',
           vary: 'Accept-Encoding',
           'content-length': '0',
           'keep-alive': 'timeout=5, max=100',
           'connection: 'Keep-Alive',
           'content-type': 'text/html' 
        },
        data: null 
    }

When I tried the synchronous call on server, I am getting "Internal Server Error" on client side. On server console, I am getting the following error.

Exception while invoking method 'get_list' Error: failed [406]
    at Object.Future.wait (/root/.meteor/tools/bebd881297/lib/node_modules/fibers/future.js:326:15)
    at Object.call (packages/meteor/helpers.js:111)
        at Object.HTTP.get (packages/http/httpcall_common.js:73)
    at Meteor.methods.get_prop_list (app/server/main.js:567:36)
    at maybeAuditArgumentChecks (packages/livedata/livedata_server.js:1346)
    at packages/livedata/livedata_server.js:539
    at _.extend.withValue (packages/meteor/dynamics_nodejs.js:35)
    at packages/livedata/livedata_server.js:538
    at _.extend.withValue (packages/meteor/dynamics_nodejs.js:35)
    at _.extend.protocol_handlers.method (packages/livedata/livedata_server.js:537)
         - - - - -
    at makeErrorByStatus (packages/http/httpcall_common.js:12)
    at Request._callback (packages/http/httpcall_server.js:99)
    at Request.self.callback (/root/.meteor/tools/bebd881297/lib/node_modules/request/request.js:129:22)
    at Request.EventEmitter.emit (events.js:98:17)
    at Request.<anonymous> (/root/.meteor/tools/bebd881297/lib/node_modules/request/request.js:873:14)
    at Request.EventEmitter.emit (events.js:117:20)
    at IncomingMessage.<anonymous> (/root/.meteor/tools/bebd881297/lib/node_modules/request/request.js:824:12)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:920:16
    at process._tickCallback (node.js:415:13)

Upvotes: 1

Views: 916

Answers (1)

musically_ut
musically_ut

Reputation: 34288

You are receiving the error 406 which means Not acceptable. From the docs:

The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request.

It suggests that either the third party server you are requesting data from is not happy with the url you are constructing in the get_list function or you are missing some headers needed for the request.

It is hard to debug beyond that without knowing what the server and its requirements are.

Upvotes: 1

Related Questions