HttpUrlConnection 到 HttpsUrlConnection,我可以只添加 's' 吗?

HttpUrlConnection to HttpsUrlConnection, can i just add the 's'?

我开发了一个 android 应用程序,它成功地将数据从我的移动应用程序发送到我的 REST service,然后使用 httpurlconnection 发送到数据库。但是,有人要求我使用 httpsurlconnection,因为 REST 服务将托管在一个安全的位置。

我的请求包括 url 然后打开一个连接 object。我有授权 headers 然后我将数据作为 JSON object.

发送

我可以简单地将 's' 添加到 httpurlconnection 还是我需要考虑哪些其他方面?

非常感谢您的帮助,谢谢!

根据 Android 文档:

Calling openConnection() on a URL with the "https" scheme will return an HttpsURLConnection

所以是的,您可以在调用 openConnection() 时简单地将返回的连接转换为 HttpsURLConnection。在大多数情况下,您不需要做任何其他事情; SSL 证书、握手以及与 HTTPS 协议相关的所有其他内容均由系统处理。