Request not working, Error: Invalid protocol: 127.0.0.1 :?

I am new to node.js, i am using request, post request.but, i got 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:

      

+3


source to share


2 answers


I write this: it works fine, you can change it like this.



     request({
           method: 'POST',
           url: 'http://127.0.0.1:3000' + '/index',
           body: {
           name: "name"
          },
          json: true
          })

      

+2


source


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



+1


source







All Articles