Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

request not work, Error: Invalid protocol: 127.0.0.1:?

I am new to node.js, I use request send the post request.but I got a error!

     request({
         method: 'POST',
         url: config.api + '/index',
         body: {
         name: "name"
        },
        json: true
      })

        throw er; // Unhandled 'error' event
        ^

         Error: Invalid protocol: 127.0.0.1:
like image 728
L.Lance Avatar asked Jul 05 '17 15:07

L.Lance


2 Answers

I write this: It work fine, you can modify it like this.

     request({
           method: 'POST',
           url: 'http://127.0.0.1:3000' + '/index',
           body: {
           name: "name"
          },
          json: true
          })
like image 80
MWY Avatar answered Nov 15 '22 05:11

MWY


Your code is incorrect: follow the instructions on the NPM module page.

like image 37
EduardoMaia Avatar answered Nov 15 '22 04:11

EduardoMaia