httprequest - 有没有办法让 HTTP 请求在准确的时间到达服务器?
问题描述
我正在创建一个发送 HTTP 请求的 nodejs 程序。我希望 HTTP 请求在准确的时间到达服务器。例如,我可能想发送一个 HTTP 请求集,并让它在 2019 年 8 月 6 日星期二下午 1:00:00 或 1565096400000(以毫秒为单位的纪元时间戳)准确地到达服务器。我该怎么做?
我考虑过的一件事是使用 setTimeout() 在某个时间为我的请求计时,但它们到达服务器的时间不一致。
这是一个使用 setTimeout 为我的请求计时的示例。在此示例中,我希望请求恰好在 1565096400000(纪元时间戳)到达服务器。
var options = {
url = 'someurl.com';
}
function callback(error, response, body) {
if(!error) {
console.log('Error.');
} else {
console.log(body);
}
}
var time_until_request = 1565096400000 - Date.now();
//We want the request to reach the server at exactly 1565096400000 (epoch //timestamp).
var timeout = setTimeout(function(){
request(options, callback);
},time_until_request);
当然,就我所做的而言,请求不会在我想要的时候到达服务器。它将在之前或之后的某个时间到达服务器 - 我相信由于延迟不一致。
解决方案
推荐阅读
- jenkins - 在 jenkins 中配置电子邮件的问题
- javascript - 在 JavaScript 中索引 HTML div 类
- python - 朴素贝叶斯多项式模型
- ios - 二元运算符“|=”不能应用于两个“UIAccessibilityTraits”操作数
- ios - Swift - 从 Firestore 中检索地理点,如何将它们显示为地图注释
- javascript - 节点代理将代理的响应缓冲区转换为字符串
- spring - 具有多个键的 Spring 可缓存注释
- python-3.x - MXNet - 稀疏矩阵的点积
- swift - 准备函数不会被 segue 调用
- python - 如何计算 STEP 文件中包含的实体几何的质心?