使用request模块进行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请求的原因吗?