达特中的net::ERR_UNSAFE_PORT

nis*_*sar 5 dart dart-html

我正在使用 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');
    });
  });
}
Run Code Online (Sandbox Code Playgroud)

客户端代码

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);
    }
  });
Run Code Online (Sandbox Code Playgroud)

M. *_*put 11

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

有些端口是为特定协议保留的,例如 HTTP 的 80 和 SSH 的 22 等。如果您将该端口用于其他类型的协议,您将面临此错误。就我而言,我使用 6000 端口作为我的后端 API 服务器,该端口已解决。我只是简单地将 6000 端口移动到 7789 所有东西都按预期工作。以下是您不得违反的特定协议的端口列表。您需要使用除此之外的端口来完成您的特定工作。


Gün*_*uer 2

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

右键单击 Chrome 快捷方式 >> 属性 >>

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

例子:

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

资源来自这里