Home  >  Q&A  >  body text

javascript - nodejs uses the require('request') module to send data and report an error

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

This is an example on the official website, but I reported an error here. error: Error: Invalid protocol: null
I don’t know the reason for the protocol
Official githubrequest

女神的闺蜜爱上我女神的闺蜜爱上我2685 days ago1029

reply all(4)I'll reply

  • 阿神

    阿神2017-07-03 11:44:31

    Solved, it should be cnpm’s fault. Use npm to reinstall the request module and it runs successfully

    reply
    0
  • 漂亮男人

    漂亮男人2017-07-03 11:44:31

    I tried it and found no problem. Did you use the webstorm debugging tool to run it?
    Or you can try reinstalling the module and try running it from the command line.
    I only saw one person with the same problem as you. Look in Stack Overflow.
    Post the link for reference. I also feel that your error message is incomplete. I suggest you post it in full.
    https://stackoverflow.com/que...

    reply
    0
  • 为情所困

    为情所困2017-07-03 11:44:31

    Has npm set up proxy?

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-07-03 11:44:31

    Is it: or:?

    reply
    0
  • Cancelreply