request not work, Error: Invalid protocol: 127.0.0.1:?
Asked Answered
D

5

5

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:
Disini answered 5/7, 2017 at 15:44 Comment(2)
The URL is missing the http:// prefix? What is the value of config.api?Stockyard
Thank you, I forget the http://. Thank you very muchDisini
T
5

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
          })
Teutonize answered 5/7, 2017 at 15:52 Comment(0)
K
1

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

Krefeld answered 5/7, 2017 at 15:47 Comment(0)
C
0

If you're using a PHP Development Server please refer to this thread for the solution. Stack Overflow

Calton answered 10/12, 2019 at 17:2 Comment(0)
D
0

I met a similar issue on Win10 after a system update. It was caused by the system proxy settings.

http_proxy=127.0.0.1:8888
https_proxy=127.0.0.1:8888

Change the above environment settings to

http_proxy=http://127.0.0.1:8888
https_proxy=http://127.0.0.1:8888

done the job for me.

Btw, if you use git-bash, you can also check the git config.

$git config --list
...
http.sslverify=false
http.proxy=http://127.0.0.1:8888
https.proxy=http://127.0.0.1:8888
...
Darken answered 29/4, 2021 at 6:10 Comment(0)
R
0

Same as in W.Perrin case, I had a cntlm proxy listening on 127.0.0.1. But in my case cntlm appeared to work only without a protocol specified. I also had to adjust http setting for every developer working on the project. So, for dev purposes, I decided to bypass proxy rules. I've followed examples given by the link NodeJS request -- how to disable automatic proxy from environment. Setting NO_PROXY variable resolved my issue.

process.env["NO_PROXY"]="*"
Rebuild answered 15/7 at 9:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.