Javascript 错误:套接字使用https挂起
我的应用程序在一段时间后崩溃,出现以下错误: {错误:connect-ETIMEDOUT 31.13.92.51:443 在Object.exports.\u errnoException(util.js:1018:11) 导出时。主机端口例外(util.js:1041:20) 在TCPConnectWrap.afterConnect[as oncomplete](net.js:1086:14)代码:“ETIMEDOUT”,错误号:“ETIMEDOUT”,系统调用:“connect”,Javascript 错误:套接字使用https挂起,javascript,node.js,sockets,Javascript,Node.js,Sockets,我的应用程序在一段时间后崩溃,出现以下错误: {错误:connect-ETIMEDOUT 31.13.92.51:443 在Object.exports.\u errnoException(util.js:1018:11) 导出时。主机端口例外(util.js:1041:20) 在TCPConnectWrap.afterConnect[as oncomplete](net.js:1086:14)代码:“ETIMEDOUT”,错误号:“ETIMEDOUT”,系统调用:“connect”, 地址:“
地址:“31.13.92.51”,端口:443} {错误:套接字挂起 在createHangUpError(_http_client.js:253:15) 在TLSSocket.socketCloseListener(_http_client.js:285:23) 在emitOne(events.js:101:20) 在TLSSocket.emit(events.js:188:7) at_handle.close(net.js:497:12) 在TCP.done[as_onclose](_tls_wrap.js:332:7)代码:'ECONNRESET'} 我没有看到我的代码中有任何错误,我如何处理这个错误
try {
https.get('https://www.instagram.com/'+username+'/?__a=1', function(resp){
var body = '';
resp.setEncoding('utf8');
resp.on('data', function (chunk) {
body += chunk;
});
resp.on('end', function () {
try {
var json = JSON.parse(body);
} catch (error) {
callback('Unable to fetch user info from Instagram.', null);
return;
}
callback(null, json.user);
});
});
}catch (error){
callback("Connection to Instagram failed.", null);
}
我尝试了同样的
https
模块,我也遇到了同样的问题,所以我决定使用另一个模块,即request
模块,它似乎工作正常。我不知道为什么,https
无法从instagram.com
获得响应,因为我已经尝试过了。这是你可以尝试的,因为它对我有用。安装请求
模块
var request = require("request");
var ext = '/?__a=1';
var username = //username here;
request
.get('https://www.instagram.com/'+ username + ext)
.on('response', function(response) {
console.log(response.statusCode) // 200 is what I get from request
console.log(response.headers['content-type'])
})
我尝试了同样的
https
模块,我也遇到了同样的问题,所以我决定使用另一个模块,即request
模块,它似乎工作正常。我不知道为什么,https
无法从instagram.com
获得响应,因为我已经尝试过了。这是你可以尝试的,因为它对我有用。安装请求
模块
var request = require("request");
var ext = '/?__a=1';
var username = //username here;
request
.get('https://www.instagram.com/'+ username + ext)
.on('response', function(response) {
console.log(response.statusCode) // 200 is what I get from request
console.log(response.headers['content-type'])
})