Android Studio HTTPS 和 SSL 证书

Android Studio HTTPS and SSL Certificate

目前,我正在使用 Android Studio 为 Android 开发移动应用程序。

到目前为止,login/senddata/getdata/viewdata 在我的本地 PC 和 HTTP 网络 中,我的移动应用程序运行得非常好。我在编码中使用 HttpUrlConnection

问题是如何在我的 HTTPS 服务器中使用 PHPMySQL 制作我的移动应用程序 run/send data/retrieve data/communicate。

它只适用于 HTTP 网络服务器。 HTTPS 根本不起作用,我的移动应用程序崩溃并停止工作。

我已经在 HTTP 和 HTTPS 服务器(SSL 和自签名证书)

中测试了我的移动应用程序

是否有任何我需要注意的编码以使其可访问 HTTPS?

谢谢。

使用自动证书你将无法工作 免费试用 ssl 7 天 https://www.globessl.com/

The official Android documentation for HTTPS 详细介绍了 HTTPS 连接在 Android 中的工作方式,包括常见错误。

如果您拥有由 CA 或经销商颁发的受信任证书,则您当前使用 HttpURLConnection 的代码应该可以正常工作。来自 https://developer.android.com/reference/java/net/HttpURLConnection.html

Calling openConnection() on a URL with the "https" scheme will return an HttpsURLConnection, which allows for overriding the default HostnameVerifier and SSLSocketFactory. An application-supplied SSLSocketFactory created from an SSLContext can provide a custom X509TrustManager for verifying certificate chains and a custom X509KeyManager for supplying client certificates.

如果您使用的是自签名证书(在生产中不推荐),this article at CodeProject 描述了处理此问题的过程。