저는 base64 인코딩을 구현하려고 시도하는 node.js 초보자입니다. 내 서버가 base64 메시지를 수신/처리하지 않는 것 같습니다. 아래 코드 :node.js - http with base64
서버 :
var http = require('http');
http.createServer(function (req, res) {
req.on('data',function(b) {
console.log("HEY!"); // <--- Never gets called
var content = new Buffer(b, 'base64').toString('utf8')
console.log("CLIENT SAID: "+content);
var msg = JSON.parse(content);
// do stuff and respond here...
});
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
클라이언트 : 내가 잘못
어떤 아이디어var http = require('http');
var options = {
hostname : 'localhost',
port : 1337,
method : 'POST'
};
var req = http.request(options, function(res) {
res.setEncoding('base64');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
// write data to request body
var msg = {'name':'Fred','age':23};
var msgS = JSON.stringify(msg);
req.write(msgS,'base64');
req.end();
을 뭘하는지?
이 좀 봐 :
이
당신이 데이터를 수집하는 것 어떻게 http://stackoverflow.com/questions/6182315/how-to-do-base64-encoding-in-node -js –