javascript - nodejs使用require('request')模块发送数据,报错
本文介绍了javascript - 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
解决方案
已解决,应该是cnpm的锅,用npm重新安装request模块,成功运行了
这篇关于javascript - nodejs使用require('request')模块发送数据,报错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文