0
Error: { [Error: connect ETIMEDOUT] code: 'ETIMEDOUT', errno: 'ETIMEDOUT', syscall: 'connect' }
hostName: 'api.v3.factual.com'
url : http://api.v3.factual.com/t/places?geo=%22$point%22:12.9361149,77.6159516]}&q=Cool%20Roll%20Burger&KEY=ApiKey
代碼
function internalHttpApiCall(hostName,url,callback)
{
var options = {
hostname : hostName,
port: 4456,
path: url,
method: 'GET',
}
/* 類似的HTTPS調用工作就好了。 我已採取以下鏈接作爲解決問題的參考。 How can I use an http proxy with node.js http.Client? How can I use an http proxy with node.js http.Client? */
var response="";
var req = http.request(options, function(res) {
console.log("statusCode: ", res.statusCode);
console.log("headers: ", res.headers);
console.log(options.path);
res.on('data', function(d) {
response += d;
});
res.on('end', function() {
if (response && JSON.parse(response))
{
var obj = JSON.parse(response)
console.log(obj);
output();
}
});
});
req.end();
req.on('error', function(e) {
console.error(e);
});
function output(xresponse)
{
callback(xresponse);
}
}
'host'而不是'hostname'? – DanFromGermany 2014-09-03 10:14:12
是的,我發佈之前嘗試過。仍然不起作用。 – 2014-09-03 10:21:19