https android 无法访问,Cordova下自签名证书无法访问https问题(IOS和Android)

这篇博客介绍了在iOS和Android平台上如何处理HTTPS请求时遇到的SSL证书错误。在iOS中,通过在appDelegate.m文件中添加代码,允许任何HTTPS证书。在Android方面,需要修改SystemWebViewClient.java文件的onReceivedSslError方法,使其默认接受SSL错误。

转载自:https://blog.csdn.net/fxp850899969/article/details/56485447

IOS上:

在appDelegate.m文件中添加以下代码:

@implementation NSURLRequest(DataController)

+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host

{

return YES;

}

@end

Android上:

修改 org.apache.cordova.engine.SystemWebViewClient.java文件中onReceivedSslError()方法为如下:

/**

* Notify the host application that an SSL error occurred while loading a resource.

* The host application must call either handler.cancel() or handler.proceed().

* Note that the decision may be retained for use in response to future SSL errors.

* The default behavior is to cancel the load.

*

* @param view The WebView that is initiating the callback.

* @param handler An SslErrorHandler object that will handle the user's response.

* @param error The SSL error object.

*/

@TargetApi(8)

@Override

public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {

handler.proceed();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值