nodejs簡單應用一(監聽服務)

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();
});
            });
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章