nodejs简单应用一(监听服务)
(浏览器请求)var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': txt_type});
response.write("This request URL was found on this server.");
}).listen(8899);
(服务器发请求)_做到跨域访问
var requestURL = function(options,response){
options = {
host: '127.0.0.1',
port: 8080,
path: '/web/index.html',
method: 'GET'
}
var site = http.createClient(options.port, options.host);
var request = site.request("GET", options.path, {'host' : path.host});
request.end();
request.on('response', function(res) {
res.on('data', function(chunk) {
response.writeHead(res.statusCode, {'Content-Type': 'text/html'});
response.write(chunk);
response.end();
});
});
}