【发布时间】:2016-08-13 21:23:09
【问题描述】:
我将以下代码用于 OpenStreetMap 查询(立交桥 API)。它适用于较小的查询,但对于较大的查询(大约需要 10 分钟),它只会生成 504 网关超时响应。
代码:
var reqStr = "http://overpass.osm.rambler.ru/cgi/interpreter?data=...
console.time("query");
var stream = request(reqStr,{timeout: 3600000}).on('error', function(err) {
console.log(err)
}).pipe(fs.createWriteStream('resultExport.json'));
stream.on('finish', function () {
console.timeEnd("query");
});
响应(resultExport.json):
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>504 Gateway Time-out</title>
</head><body>
<h1>Gateway Time-out</h1>
<p>The gateway did not receive a timely response
from the upstream server or application.</p>
</body></html>
查询命令有一个 [timeout:3600](秒),请求得到 {timeout:3600000}(毫秒)。我还能做些什么来防止超时并获得正确的响应?我有点困惑这是从哪里来的。
【问题讨论】:
标签: json node.js request openstreetmap overpass-api