Created
October 25, 2010 06:21
-
-
Save daralthus/644491 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//the most simple http client: | |
//http://nodejs.org/api.html#http-client-183 | |
//dependencies | |
var http = require('http') //http module | |
, sys = require('sys'); //some node core utils | |
//setup the request (this is something like curl...) | |
var httpclient = http.createClient( 80, 'finance.yahoo.com' ) | |
, page = "/"; | |
//the request | |
var request = httpclient.request( 'GET', page | |
, {'host': 'finance.yahoo.com'} | |
, {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' } | |
, {'Accept-Language': 'en-us,en;q=0.5'} | |
, {'Accept-Encoding': 'gzip,deflate'} | |
, {'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7'} | |
, {'Keep-Alive': '115'} | |
, {'Connection': 'keep-alive'} | |
, {'Referer': 'http://finance.yahoo.com/q?s=aapl'}); //the request header we are sending. | |
request.end(); | |
//listening for the response | |
request.on('response', function (response) { | |
console.log('STATUS: ' + response.statusCode); //print to console | |
console.log('HEADERS: ' + JSON.stringify(response.headers)); | |
response.setEncoding('utf8'); | |
response.on('data', function (chunk) { | |
console.log('BODY: ' + chunk); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment