Schreiben Sie formatierte JSON in Node.js

Ich bin mit Node.js POST JSON zu PostBin aber die Daten werden falsch formatiert (wie man hier sehen kann: http://www.postbin.org/1cpndqw).

Dies ist der code den ich verwende für den tesT:

var http = require('http');

var options = {
  host: 'www.postbin.org',
  port: 80,
  path: '/1cpndqw',
  method: 'POST'
};

var req = http.request(options, function(res) {
  console.log('STATUS: ' + res.statusCode);
  console.log('HEADERS: ' + JSON.stringify(res.headers));
  res.setEncoding('utf8');
  res.on('data', function (chunk) {
    console.log('BODY: ' + chunk);
  });
});

req.write(JSON.stringify({ a:1, b:2, c:3 }, null, 4));
req.end();

InformationsquelleAutor der Frage donald | 2011-04-17

Schreibe einen Kommentar