使用请求模块发出 HTTP 请求时是否可以指定端口号?我在文档中没有看到任何有关此内容的信息:
var request = require('request');
// this works
request({
method: 'GET',
url: 'http://example.com'
}, function(error, response, body) {
if (error) console.log(error);
console.log(body);
});
// this does not work
request({
method: 'GET',
url: 'http://example.com:10080'
}, function(error, response, body) {
// ...
});
此外,当我运行第二个版本时,我的程序中绝对没有任何反应(几乎就像从未发出请求一样)。
我还知道我可以在使用核心发出请求时指定端口号http
模块。为什么请求模块中没有这个选项?
编辑:我应该之前提到过这一点,但我正在 Heroku 上运行这个应用程序。
当我在本地运行请求(使用请求模块)时,我可以指定端口号,并获得成功的回调。
当我从 Heroku 运行请求时,没有触发任何回调,并且 nginx 没有显示该请求的记录。
我疯了吗? Heroku 是否有某种原因阻止我向特定端口号发出出站 HTTP 请求?