我的数据库中有超过2000个用户,当我尝试向所有用户广播一条消息时,它几乎没有发送大约200个请求,然后我的服务器停止,我得到一个如下错误:从Node.js发送多个请求到一个API会导致错误
{ Error: connect ETIMEDOUT 31.13.88.4:443
at Object.exports._errnoException (util.js:1026:11)
at exports._exceptionWithHostPort (util.js:1049:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect,
address: '31.13.88.4',
port: 443 }
有时候我得到另一个错误,说:
Error!: Error: socket hang up
这是我的要求:
function callSendAPI(messageData) {
request({
uri: 'https://graph.facebook.com/v2.6/me/messages',
qs: { access_token: '#####' },
method: 'POST',
json: messageData
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
var recipientId = body.recipient_id;
var messageId = body.message_id;
if (messageId) {
console.log("Successfully sent message with id %s to recipient %s",
messageId, recipientId);
} else {
console.log("Successfully called Send API for recipient %s",
recipientId);
}
} else {
console.error("Failed calling Send API");
console.log(error)
}
});
}
我已经试过
setTimeout
做出了一会儿的API调用wait:
setTimeout(function(){callSendAPI(data)},200);
谁能帮助他/她面临着类似的错误?
我使用Messenger平台支持呼叫发送API率高并且不与200个呼叫限制编辑。
请首先搜索谷歌搜索错误:https://www.google.com/search?q=ETIMEDOUT+node.js – mplungjan
@mplungjan我做了,但我还没有找到与http.request相关的答案 –
q = ETIMEDOUT + node.js + POST + facebook – mplungjan