Created
July 6, 2011 15:04
-
-
Save jeremyroman/1067452 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
var http = require('http'), | |
qs = require('querystring'); | |
var body = qs.stringify({ method: 'system.connect' }); | |
var options = { | |
host: 'www.goworkit.com', | |
port: 80, | |
path: '/services/json/', | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/x-www-form-urlencoded', | |
'Content-Length': body.length, | |
'Accept': '*/*' | |
} | |
}; | |
var req = http.request(options, function(res) { | |
console.log('STATUS: ' + res.statusCode); | |
console.log('HEADERS: ' + JSON.stringify(res.headers)); | |
res.setEncoding('utf8'); | |
res.on('data', function(chunk) { | |
console.log('BODY: ' + chunk); | |
}); | |
}); | |
req.on('error', function(e) { | |
console.log('problem with request: ' + e.message); | |
}); | |
// write data to request body | |
req.end(body); |
Also, thanks for proofreading all of my gists. :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
end takes an optional argument which is something to write before ending.
http://nodejs.org/docs/v0.4.9/api/http.html#request.end
Also, I'm writing to the request body, not the response body, because this is an HTTP client not an HTTP server.