gpt4 book ai didi

android - 如何使用 Retrofit 的输入流加载 SSL 证书

转载 作者:太空宇宙 更新时间:2023-11-03 14:23:28 25 4
gpt4 key购买 nike

我需要为 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/

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