您的位置:首页技术文章
文章详情页

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

浏览:38日期:2023-08-26 13:58:25

问题描述

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.});

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

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

问题解答

回答1:

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

回答2:

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

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

回答3:

是不是 npm 设 proxy 了

回答4:

是:还是:?

标签: JavaScript
相关文章: