Using q-io/http to pull in a web page is failing. I think I must be missing something obvious - because this is what I think is a pretty straight forward example.
Edit: windows 8, node 11.13
var http = require('q-io/http')
var url = 'http://www.google.com' ;
http.request({
method: 'GET',
uri: url
}).
then(function (response) {
console.log(response)
}).
fail(function (err) {
console.error(err)
});
Here is the output:
{ state: 'pending' }
> { [Error: connect ETIMEDOUT]
stack: 'Error: connect ETIMEDOUT\n at exports._errnoException (util.js:742:11)\n at Object.afterConnect [as oncomplete] (net.js:989:19)',
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect' }
This is slightly different than the duplicate. q-io/http will close the request AFTER you read the body. Reading the body looks to be essential here.
Well changing the code to this:
var http = require('q-io/http')
var url = 'http://www.google.com' ;
results = qHttp.request({ url: url }).then(function(res){
return res.body.read().then(function(bodyStream){
var body = bodyStream.toString('UTF-8')
return body
})
})
accessing the response body looks to solve the problem, my assumption is that the stream is getting closed within the confines of q-io/http (which is wrapping the Node/http library). I spent some time tracing the code - but cannot find the exact path to the .end()