jxson
10/13/2011 - 8:30 PM

http-browserify example

http-browserify example

      http = require('http');

      var options = {
        host: 'localhost',
        port: '1337',
        path: '/',
        // NOTE: Headers can't be set until after the xhr is opened
        // https://github.com/substack/http-browserify
        // headers: {
        //   'Accept': 'application/json'
        //   'origin': 'http://localhost:8080'
        // }
      }

      http.get(options, function(response){
        response.on('data', function(buffer){
          console.log('buffer', buffer);
        });

        response.on('end', function(){
          console.log('data', response);
        });
      });