“是否可以取消请求?”
HTTP.call() 似乎没有返回一个我们可以调用类似stop() 方法的对象。也许解决方案是阻止基于 Session 变量执行回调?
HTTP.call("GET", url, function(error, result) {
if (!Session.get("stopHTTP")) {
// Callback code here
}
});
然后,当您到达要取消请求的地步时,请执行以下操作:
Session.set("stopHTTP", true);
在服务器上,也许您可以使用environment variable 而不是environment variable?
请注意,HTTP.call() 选项对象确实接受 timeout 键,因此如果您只是担心请求永远不会超时,您可以将其设置为您想要的任何毫秒整数。
“是否可以有多个查询参数共享同一个键?”
是的,这似乎是可能的。这是我使用的一个简单测试:
流星代码:
HTTP.call("GET", "http://localhost:1337", {
query: "id=foo&id=bar"
}, function(error, result) {
// ...
});
单独的 Node.js 服务器:(只是 Node.js 主页上的基本示例,用 console.log 行输出带有查询字符串的请求 URL)
var http = require('http');
http.createServer(function(req, res) {
console.log(req.url); // Here I log the request URL, with the query string
res.writeHead(200, {
'Content-Type': 'text/plain'
});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
当 Meteor 服务器运行时,Node.js 服务器会记录:
/?id=foo&id=bar
当然,这仅适用于 GET URL 查询参数。如果您需要为 POST 参数执行此操作,也许您可以将单独的值存储为带有 EJSON.stringify 的序列化数组字符串?