1、获取证书
1.通过openssl命令获取,命令如下(以百度为例):
openssl s_client -connect www.baidu.com:443 /dev/null | openssl x509 -outform DER > https1.cer
这个命令的目的就是直接在你的终端打开的当前目录下面下载某一站点的证书,但是我怎么都获取不到下载的证书都是空的,而且终端还报错,找不到错误的原因,没办法只能用第二种办法了

2.直接在浏览器中打开项目的任意一个接口的完整路径,如果你服务器支持https的话会在链接的前面出现一个小锁的图标(我使用的是safair浏览器),点击小锁会出现提示点击显示证书就会出现站点证书的信息了(以百度为例),点击证书的图标到桌面上就可以把证书下载到桌面上了,这样就获取到站点证书了(这种方式不知道会不会存在啥问题,但是到目前为止我没遇到啥问题)

获取到证书后把证书放到项目的mainbundle中,并用代码获取

参考链接
https://www.jianshu.com/p/fa65eb0460dc
网友评论