I wonder why such simple http request is not working...
http = require("http")
url = "http://nodejs.org/"
console.log "Try a request to #{url}..."
reqHttp = http.request url, (response) ->
console.log "Request to #{url}"
response.on 'data', (chunk) -> console.log "chunk: ", chunk
reqHttp.on 'error', (error) -> console.log "reqHttp error", error
After a minute or so it returns:
reqHttp error { [Error: socket hang up] code: 'ECONNRESET' }
To make sure it is not a problem on my environment, I tried the request module and worked just fine:
request = require("request")
url = "http://nodejs.org/"
request url, (error, response, body) ->
console.log body if not error and response.statusCode is 200
It seems I'm not the only one.
So, I have a workaround for my problem (using request module), but I'd like to know why I can't use the buind-in http request. Is it buggy or unreliable? (Node.js version 0.8.21)