【问题标题】:Dart/Flutter using HTTP to connect to Springboot apiDart/Flutter 使用 HTTP 连接 Springboot api
【发布时间】:2019-07-05 08:44:55
【问题描述】:

我正在使用http(dart包)连接到本地部署的springboot api, 但是,应用程序抛出 Connection denied 错误 111 并显示错误的端口

尝试打开端口看看是否有帮助,将本地主机替换为计算机 ipm 更改了 springboots 端口,但问题仍然存在。

连接服务器的线路

final response = await http.get('http://localhost:8080/api/v1/alltables');

控制台日志错误:

ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter (27342): SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 49588

【问题讨论】:

    标签: android spring-boot http dart flutter


    【解决方案1】:

    尝试关闭服务器计算机防火墙或在防病毒程序中为 IP 地址添加例外。 此外,如果您使用的是子网 IP 地址,请确保您的服务器计算机和移动设备连接到同一网络。

    【讨论】:

      【解决方案2】:

      将 localhost 更改为 10.0.2.2。

      【讨论】:

        【解决方案3】:

        尝试在 rest 控制器类中的 spring boot 中启用交叉原点( 它对我有用)

        @CrossOrigin(origins = {"http://localhost:4200", "http://10.0.2.2:8080"})
        @RestController
        @RequestMapping("/api")
        public class UsuarioClienteRestController {......}
        

        "http://localhost:4200" 用于角度(网络)

        "http://10.0.2.2:8080" 用于颤振

        【讨论】:

          猜你喜欢
          • 2020-07-17
          • 2020-05-05
          • 2018-08-12
          • 2021-11-16
          • 1970-01-01
          • 2021-10-25
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多