https android cannot be accessed, self-signed certificate under Cordova cannot access https problem (IOS and Android)

Reprinted from: https://blog.csdn.net/fxp850899969/article/details/56485447

On IOS:

Add the following code to the appDelegate.m file:

@implementation NSURLRequest(DataController)

+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host

{

return YES;

}

@end

On Android:

Modify the onReceivedSslError() method in the org.apache.cordova.engine.SystemWebViewClient.java file as follows:

/**

* 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();

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324480592&siteId=291194637