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

Ionic Android应用HTTPS连接本地Spring Boot服务器握手失败问题

解决方案

1. 更新Network Security Config配置

当前配置仅信任localhost,但模拟器访问本地主机使用10.0.2.2,需添加该域名并明确信任自签名证书:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="false">
        <domain includeSubdomains="true">localhost</domain>
        <domain includeSubdomains="true">10.0.2.2</domain>
        <trust-anchors>
            <!-- 引用res/raw目录下的自签名证书文件(不带后缀) -->
            <certificates src="@raw/your_cert_file" />
            <!-- 可选:保留系统证书信任,避免影响其他HTTPS请求 -->
            <certificates src="system" />
        </trust-anchors>
    </domain-config>
</network-security-config>

2. 验证Spring Boot HTTPS配置

确保application.properties中HTTPS参数配置正确,示例:

server.port=8443
server.ssl.key-store-type=PKCS12
server.ssl.key-store=classpath:keystore.p12
server.ssl.key-store-password=your_keystore_pass
server.ssl.key-alias=your_cert_alias

在模拟器浏览器中访问https://10.0.2.2:8443,确认服务器能正常响应(忽略浏览器的不安全提示)。

3. 检查Ionic请求地址

确保所有API请求都使用https://10.0.2.2:8443(对应Spring Boot的HTTPS端口),避免HTTP与HTTPS混合调用。

4. 确认证书格式与放置位置

将自签名证书转换为PEM格式后,放入Ionic Android项目的res/raw目录。转换命令示例:

keytool -exportcert -alias your_cert_alias -keystore keystore.p12 -rfc -file certificate.pem

5. 清理缓存并重新构建

  • 在Android Studio中执行Build > Clean Project,再执行Build > Rebuild Project
  • 重启模拟器,清除应用缓存后重新测试

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 15:22:39