nodejs使用require('request')模块发送数据,报错

var request = require('request');
request('http://www.baidu.com', function (error, response, body) {
    console.log('error:', error); // Print the error if one occurred
    console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
    console.log('body:', body); // Print the HTML for the Google homepage.
});

图片描述

这是官网上的实例,但是我这边报错。error: Error: Invalid protocol: null
不知道什么协议的原因
官方githubrequest

阅读 7.7k
4 个回答

已解决,应该是cnpm的锅,用npm重新安装request模块,成功运行了

我试了一下,是没有发现问题的,你是用webstorm的调试工具运行的吗?
或者可以尝试一下重新安装模块,再用命令行运行试一下。
只看到一个跟你一样问题的 看 Stack Overflow里面
贴上连接参考一下,还有感觉你的报错信息也不完整建议贴全一点
https://stackoverflow.com/que...

图片描述

是不是 npm 设 proxy 了

是:还是:?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题