如何使用输入流加载SSL证书进行翻新

我需要为Android中的Retrofit添加SSL证书,但我无法使用Google的示例代码找到该文件。

以下是我使用https://developer.android.com/training/articles/security-ssl

的Google示例

运行时:

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为什么找不到它?

liuqingsong123 回答:如何使用输入流加载SSL证书进行翻新

执行以下操作:

InputStream cert = context.getResources().openRawResource(R.raw.my_cert); 
// Place your 'my_cert.crt' file in `res/raw`
,

原来我已经导入

android.R

代替

com.myApp.R

更改此设置后,我可以找到自己的证书并将其导入。

本文链接:https://www.f2er.com/3125590.html

大家都在问