You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter 3.29.3调用SpringBoot API出现连接超时问题求助

Flutter 3.29.3升级后物理设备无法连接本地SpringBoot HTTPS服务(连接超时)

将Flutter版本升级至3.29.3后,物理手机上运行的Flutter应用无法连接本地SpringBoot应用:使用Postman发送POST请求至https://localhost/auth/authenticate可正常获取access_token,但手机端出现连接超时错误。

证书生成命令

使用openssl生成证书的命令如下:

openssl.exe req -newkey rsa:2048 -keyout PRIVATEKEY.key -out MYCSR.csr

openssl.exe req -new -x509 -nodes -sha256 -days 365 -key PRIVATEKEY.key -out host.cert

openssl.exe pkcs12 -export -in host.cert -inkey PRIVATEKEY.key -out keystore.p12 -name myApp

物理设备上的错误日志

I/flutter ( 3796): ClientException with SocketException: Connection timed out (OS Error: Connection timed out, errno = 110), address = 192.168.1.40, port = 37950, uri=https://192.168.1.40/auth/authenticate
I/.example.xplore( 3796): Thread[2,tid=3802,WaitingInMainSignalCatcherLoop,Thread*=0xb40000732bd83c00,peer=0x15440320,"Signal Catcher"]: reacting to signal 3
I/.example.xplore( 3796): 
I/.example.xplore( 3796): Wrote stack traces to tombstoned
D/Looper  ( 3796): dumpMergedQueue
D/OplusLooperMsgDispatcher( 3796): dumpMsgWhenAnr

本地环境与Flutter配置

  • 电脑本地IP:192.168.1.40
  • 开发环境下重写的HttpOverrides代码:
class MyHttpOverrides extends HttpOverrides {
  @override
  HttpClient createHttpClient(SecurityContext? context) {
    return super.createHttpClient(context)
      ..badCertificateCallback =
          (X509Certificate cert, String host, int port) => true;
  }
}

Flutter请求代码

var response = await http.post(Uri.parse(login),
          headers: {"Content-Type": "application/json"},
          body: jsonEncode(reqBody))

请帮忙排查问题,如需更多信息请告知!

内容的提问来源于stack exchange,提问作者dusk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 06:30:12