net::ERR_UNSAFE_PORT 飞镖

net::ERR_UNSAFE_PORT in dart

我正在使用 notepad++ 编写服务器端 dart 代码,我已经使用 dart 编辑器在服务器端 dart 代码中取得了成功。但我同样认为我用 notepad++ 完成的地方在浏览器中的 dart 中出现了 net::ERR_UNSAFE_PORT 错误,由命令提示符初始化的 Dart 服务器端已完成,当我尝试访问 172....190 时,Bowser(dartium)说上面的错误!!!

服务器端代码

main() {
  HttpServer.bind("172...", 4045).then((server) {
    server.listen((res) {
      res.response.headers.add("Access-Control-Allow-Origin", "172.25.10.181");
      res.response.headers
          .add("Access-Control-Allow-Methods", "POST,GET,DELETE,PUT,OPTIONS");
      res.response.headers.add('Access-Control-Allow-Headers',
          'Origin, X-Requested-With, Content-Type, Accept,application/x-www-form-urlencoded');
      print('I am writing server side code');
    });
  });
}

客户端代码

req = new HttpRequest();

  req.open('get', 'http://172...:4045');

  req.send(data);

  req.onReadyStateChange.listen((_) {
    if (req.readyState == HttpRequest.DONE &&
        (req.status == 200 || req.status == 0)) {
     print(req.responseText);
    }
  });

无耻复制自https://superuser.com/questions/188006/how-to-fix-err-unsafe-port-error-on-chrome-when-browsing-to-unsafe-ports

Right Click on Chrome shortcut >> Properties >>

然后追加 --explicitly-allowed-ports=xxx 到快捷方式目标

示例:

C:\Documents and Settings\User\Local Settings\Application Data\Google\Chrome\Application\chrome.exe --explicitly-allowed-ports=6666

资源来自 here

某些版本的 Chrome 中存在错误,导致给定的 --explicitly-allowed-ports 解决方案无法工作。在这种情况下,临时 解决方法是:

  1. 浏览至 chrome://flags/#network-service。
  2. 将“启用网络服务”设置为禁用。
  3. 重新启动Chrome。

Reference

这是处理此问题的最佳方法。

There some ports are reserved for specific protocols like 80 for HTTP and 22 for SSH etc. If you use that port for another kind of protocol you will face this error. In my case, I'm using 6000 port for my backend API server which was resolved. I just simply move 6000 port to 7789 all stuff working as expected. Here are the list ports for specific protocols that you may not violate. You need to use port other then this for your specific work.