Search code examples
node.jsrequest

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:

Solution

  • 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
              })