node.js - API request in Node returning error -


i making simple http request sphere engine api request parameters . however, cannot interpret error . api specification : http://sphere-engine.com/services/docs/compilers#status

code:

http = require('http') ;  var info = {     sourcecode: 'print 3+4',     language: 4,     input: '' } ;  var infostring = json.stringify(info);  var options = {     host: 'api.compilers.sphere-engine.com',     port: 80,     path: '/api/v3/submissions?access_token=b11bf50b8a391d4e8560e97fd9d63460',     method: 'post',     headers: {         'content-type': 'application/json',         'content-length': infostring.length     } } ;  var req = http.request(options,function(res) {     res.setencoding('utf-8');     var responsestring = '' ;     res.on('data', function(data) {         responsestring += data ;     });     res.on('end', function() {         var resultobject = json.parse(responsestring);     }); } );  req.write(infostring); req.end(); 

error:

undefined:0  ^ syntaxerror: unexpected end of input     @ object.parse (native)     @ incomingmessage.<anonymous> (/users/sarthakmunshi/nodetry.js:29:27)     @ incomingmessage.emit (events.js:117:20)     @ _stream_readable.js:943:16     @ process._tickcallback (node.js:419:13) 

this error caused json.parse(responsestring);. response not-json string (xml, html?), try parse json.

you can use xml-stream library parse xml.


Comments