简体   繁体   English

请求无效,错误:无效协议:127.0.0.1:?

[英]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!我是 node.js 的新手,我使用 request 发送 post request.but 我得到了一个错误!

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

        throw er; // Unhandled 'error' event
        ^

         Error: Invalid protocol: 127.0.0.1:

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

Your code is incorrect: follow the instructions on the NPM module page .您的代码不正确:按照NPM 模块页面上的说明进行操作。

If you're using a PHP Development Server please refer to this thread for the solution.如果您使用的是 PHP 开发服务器,请参阅此线程以获取解决方案。 Stack Overflow 堆栈溢出

I met a similar issue on Win10 after a system update.系统更新后,我在Win10上遇到了类似的问题。 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-bash ,你还可以检查git配置。

$git config --list
...
http.sslverify=false
http.proxy=http://127.0.0.1:8888
https.proxy=http://127.0.0.1:8888
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM