javascript - Making asynchronous requests within a Node.js server error:"TypeError: Object #<Object> has no method '_implicitHeader'" -
so trying make server receive request, make new request, receive new response, , relay original source.
here code:
var http = require('http'); var request = require('request'); var server = http.createserver(function(request, response){ response.writehead(200, {"content-type": "text/plain"}); response.write('on'); getsummonerid(response); }); server.listen(9000); console.log("server running!"); function getsummonerid(cb){ request('https://na.api.pvp.net/api/lol/na/v1.4/summoner/by-name/' + 'someones-name' + '?api_key=mykeygoeshere', function(request, response, body){ cb(json.parse(body)); }); }
when did that, got typeerror: object #<object> has no method '_implicitheader'
.
upon further searching through tome of googel, found these:
https://github.com/joyent/node/issues/5597
how can implement nodejs stream api?
i think might problem i'm having, i'm having trouble translating context of original question context of problem.
well, think there multiple issues here, big 1 passing response
object getsummonerid()
function callback, it's not function, it's object. how trying this:
var http = require('http'); var request = require('request'); var server = http.createserver(function(request, response){ response.writehead(200, {"content-type": "text/plain"}); // response.write('on'); // why have this? getsummonerid(function(data) { // notice pass in function, keep response handling here response.end(json.stringify(data)); // http responses must strings }); }); server.listen(9000); console.log("server running!"); function getsummonerid(cb){ request('https://na.api.pvp.net/api/lol/na/v1.4/summoner/by-name/' + 'someones-name' + '?api_key=mykeygoeshere', function(request, response, body){ cb(json.parse(body)); }); }
Comments
Post a Comment