gpt4 book ai didi

java - Android Studio HTTPS 和 SSL 证书

转载 作者:太空宇宙 更新时间:2023-11-03 13:44:10 26 4
gpt4 key购买 nike

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

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

问题是如何让我的移动应用程序在我的 HTTPS 服务器中运行/发送数据/检索数据/与 PHPMySQL 通信。

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

我已经在 HTTP 和 HTTPS 服务器(SSL 和自签名证书)中测试了我的移动应用

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

谢谢。

最佳答案

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描述了处理此问题的过程。

关于java - Android Studio HTTPS 和 SSL 证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39607196/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com