DelphiXE10.3 开发 android 安卓 app 访问 https 服务端

    xiaoxiao2022-07-15  144

    Play Store 已经发布通知了,将在 2019年8月份的新APP必须使用https通讯方式才能上架市场。

    现分享我在DelphiXE开发的安卓APP添加HTTPS通讯方式的实现方式

    版本 DelphiXE10.3 + Indy10.6.2.5366 + openssl

    步骤:

    1、建立多媒体应用,设置项目 Target Platforms 为 Android ,Android SDK使用 25版本。

    2、窗体拉入 idhttp 和 IdSSLIOHandlerSocketOpenSSL,设置 idhttp 里的 IOHandler 参数指向刚才的IdSSLIOHandlerSocketOpenSSL组件,设置 IdSSLIOHandlerSocketOpenSSL 里面的 SSLOptions 参数为 sslvTLSv1。

    3、下载openssl 的 so 文件(下载地址:http://nicedac.com/file/a94194ea83a0362e.html),将两个so文件放到项目方法:点击 Project -> Deployment -> All Configurations -> android platform -> Add file -> select your libraries ,将两个 so 文件加入,并且都设置 remote path for files to: .\assets\internal\

    4、点击 Project -> View Source ,在初始化段落里添加  IdOpenSSLSetLibPath(TPath.GetDocumentsPath); 

    begin Application.Initialize; {$IFDEF ANDROID} IdOpenSSLSetLibPath(TPath.GetDocumentsPath); {$ENDIF} Application.CreateForm(THeaderFooterwithNavigation, HeaderFooterwithNavigation); Application.Run; end.

    5、使用 idhttp组件访问 https 网站测试

    IdHTTP1.get('https://www.baidu.com');

    完成,发布APK输出测试

    最新回复(0)