我创建了一个PhoneGap的应用程序,它需要使用自签名的SSL服务进行通信。
我列入白名单我的网址在res / XML / cordova.xml像这样:
<access origin="https://www.mydomain.com" subdomains="true" />
这工作得很好,当我运行,并从Eclipse构建,但如果我再出口,并签署我的应用程序和手动安装APK然后应用程序是无法使用网络服务进行通信。
与服务器的通信进行使用煎茶触摸库就像这样:
Ext.Ajax.request({
url: 'https://www.mydomain.com',
method: 'get',
success: function(result) {
},
failure: function(result) {
}
});
任何帮助非常赞赏
问题是你使用的是自签名的证书。 而Android的WebView默认不自签名的SSL证书允许。 PhoneGap的/科尔多瓦覆盖这在CordovaWebViewClient类 ,但不被太多偏离其行为; 如果应用程序的调试签署,它将proceed
并忽略该错误,否则就会失败。
你可以改变上面的链接代码在你的应用程序,使onReceivedSslError
方法总是调用handler.proceed()
-但不建议这样做。 不要使用自签名证书!
我做了以下绕过限制(目前使用的科尔多瓦1.7.0)。 这绝对是固有的不安全:
public class MyWebViewClient extends CordovaWebViewClient {
public MyWebViewClient(DroidGap ctx) {
super(ctx);
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
// testing against getPrimaryError() or hasErrors() will fail on Honeycomb or older.
// You might check for something different, such as specific info in the certificate,
//if (error.getPrimaryError() == SslError.SSL_IDMISMATCH) {
handler.proceed();
//} else {
// super.onReceivedSslError(view, handler, error);
//}
}
}
然后在主要活动:
@Override
public void init() {
super.init();
//pass in our webviewclient to override SSL error
this.setWebViewClient(this.appView, new MyWebViewClient(this));
}
文章来源: Phonegap/Cordova whitelisted cross domain SSL request not working after exporting APK