【发布时间】:2012-04-01 00:18:02
【问题描述】:
我有一些如下所示的 node.js 代码:
Updater.prototype.poll= function(callback) {
var options = {
host: api_host,
port: 80,
path: update_path,
method: 'GET',
agent: false,
headers: [{'accept-encoding': '*;q=1,gzip=0'}]
};
console.log('Polling');
var req = http.get(options, function(res) {
//other stuff here...
});
};
问题是发送请求时,服务器返回400 Bad Request - Invalid Hostname。我已经用wireshark嗅探了TCP流,它似乎没有发送http请求的Host部分,而是生成了一条看起来像:undefined: undefined的行。我确定api_host 变量设置正确(我什至尝试使用硬编码字符串)。我也尝试过使用 hostname 而不是 host 。是否有已知的原因可能会以这种方式运行?
【问题讨论】:
-
还有options的价值是什么?