我需要为 Android 中的 Retrofit 添加我的 SSL 证书,但我无法使用 Google 的示例代码找到该文件。
这是我使用的 Google 示例 https://developer.android.com/training/articles/security-ssl
运行时:
val caInput: InputStream = BufferedInputStream(FileInputStream("rest_of_the_world_production.crt"))
我得到了错误
Caused by: java.io.FileNotFoundException: rest_of_the_world_production.crt: open failed: ENOENT (No such file or directory)
并在尝试访问文件时立即崩溃。该文件当前作为 crt 文件存储在 res/raw/rest_of_the_world_production.crt 下,为什么 Android 找不到它?
最佳答案
按如下方式进行:
InputStream cert = context.getResources().openRawResource(R.raw.my_cert);
// Place your 'my_cert.crt' file in `res/raw`
关于android - 如何使用 Retrofit 的输入流加载 SSL 证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58798013/