天天看点

处理 unity使用UnityWebRequest访问https网站报错 Trust anchor for certification path not found.

最近公司接了一个新项目,使用的是https,刚开始使用的www post方式来访问域名获取二维码,在编辑器上面完全正常,放到安卓上运行报错:javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.找了两天资料,在Androidstudio里面也做了处理,但是没用。后面将www换成UnityWebRequest请求,并且把证书屏蔽,就正常了。

1.先贴上证书代码:如果继承不了这个证书类的话就将.net版本升级到4.0以上

处理 unity使用UnityWebRequest访问https网站报错 Trust anchor for certification path not found.
处理 unity使用UnityWebRequest访问https网站报错 Trust anchor for certification path not found.

2.贴上post访问代码,type不传的话也可以,看自己的项目需求,data的话,用字典把需要的参数保存,再转换成字符串

处理 unity使用UnityWebRequest访问https网站报错 Trust anchor for certification path not found.
处理 unity使用UnityWebRequest访问https网站报错 Trust anchor for certification path not found.

3.打包测试,建议可以先做个demo,再加入项目当中去。

4.如果没有证书屏蔽代码的话,会报一个未知错误。

5.希望对大家有所帮助