gpt4 book ai didi

javascript - 错误: socket hang up using https

转载 作者:行者123 更新时间:2023-12-01 03:11:34 24 4
gpt4 key购买 nike

我的应用程序在一段时间后崩溃并出现以下错误:

{ Error: connect ETIMEDOUT 31.13.92.51:443 at Object.exports._errnoException (util.js:1018:11) at exports._exceptionWithHostPort (util.js:1041:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14) code: 'ETIMEDOUT', errno: 'ETIMEDOUT', syscall: 'connect',
address: '31.13.92.51', port: 443 }

{ Error: socket hang up at createHangUpError (_http_client.js:253:15) at TLSSocket.socketCloseListener (_http_client.js:285:23) at emitOne (events.js:101:20) at TLSSocket.emit (events.js:188:7) at _handle.close (net.js:497:12) at TCP.done [as _onclose] (_tls_wrap.js:332:7) code: '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'])
})

关于javascript - 错误: socket hang up using https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45804280/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com