将我的 Flutter 版本升级到 3.29.3 后:
Flutter 3.29.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision ea121f8859 (2 weeks ago) • 2025-04-11 19:10:07 +0000
Engine • revision cf56914b32
Tools • Dart 3.7.2 • DevTools 2.42.3
我无法连接我的 SpringBoot 应用。我使用 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
使用 Postman,我的请求:https://localhost/auth/authenticate
根据POST
请求运行良好并提供我的 access_token。
现在,当我在实体手机上启动 Flutter 应用程序时,出现以下错误:
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
我的计算机上的本地 IP 地址(ipconfig)是192.168.1.40。
在我的 main.dart 中,我覆盖了createHttpClient
(我认为这仅适用于 DEV,不适用于 PROD):
class MyHttpOverrides extends HttpOverrides {
@override
HttpClient createHttpClient(SecurityContext? context) {
return super.createHttpClient(context)
..badCertificateCallback =
(X509Certificate cert, String host, int port) => true;
}
}
我POST
在 Flutter 应用程序中的请求如下所示:
var response = await http.post(Uri.parse(login),
headers: {"Content-Type": "application/json"},
body: jsonEncode(reqBody))
如果您需要更多信息,请问我:)
感谢您的帮助!
确保:
手机和电脑在同一个Wi-Fi上
防火墙暂时禁用
Spring Boot 绑定在 0.0.0.0
在 Flutter 应用中使用正确的 IP 和端口