var http = require('http');
var fs = require('fs');
var server = http.createServer(function(req, res) {
if (req.url !== "/favicon.ico") {
req.on('data', function(data) {
console.log('服務器端接受到的數據: ' + decodeURIComponent(data));
res.write('服務器端接受到的數據: ' + decodeURIComponent(data));
});
res.writeHead(200, {
'Content-Type': 'text/plain',
'Access-Control-Allow-Origin': 'http://localhost'
});
//這兩句等同於上面的res.writehead();
// res.setHeader('Content-Type': 'text/plain');
// res.setHeader('Access-Control-Allow-Origin':'http://localhost');
res.write('<html><head><meta charset="utf-8"/></head></html>');
res.write("服務器發來的數據"); }
res.end();
}).listen(1337, "127.0.0.1");