node.js 请求模块给出 http 调用错误 [错误 : Invalid protocol: null]

标签 node.js proxy request

我正在使用 Node.js 的请求模块对地址如下的 api 进行 HTTP GET 调用:http://x.x.xxx.xx:8000/names 但调用返回错误[错误:协议(protocol)无效:null]

我的 API 调用如下所示:

request.get({
    uri: 'http://x.x.xxx.xx:8000/names'
}, function(err, res, body){
    if(err == null){
        res.status(200).send(data);
    }else{
        console.log(err);
    }});

注意:我通过“npm config set proxy”和“npm config set https proxy”使用了npm代理。删除它们也不能解决问题。

谢谢

最佳答案

既然这样,工作得很好,我会说问题出在你的代理配置中。

request.get({
    uri: 'http://localhost:8000/names'
}, function(err, res, body){

});

试试这个:

npm config set proxy http://usr:pwd@host:port

关于node.js 请求模块给出 http 调用错误 [错误 : Invalid protocol: null],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34964935/

相关文章:

javascript - 用 Restify 抽象 Mongoose

node.js - 如何优雅地关闭 mongoose 的连接池?

jquery - 在 Jade 和 Bootstrap 中使用 Dropdowns 给我 $ (".dropdown-toggle")。dropdown 不是函数

c++ - C++ 中的 HTTP 代理服务器

angular - 覆盖 Angular httpclient get 请求上的基本 URL

javascript - 如何下载整个 NPM 存储库以获得完全离线开发的乐趣?

终端服务器上的 Apache 代理 CORS 关闭或超时

ruby - 如何在 Ruby 中检查代理是否可连接?

arrays - Swift HTTP POST 二维数组

c# - IMGUR 照片上传 POST 请求