Ionic学习笔记五 跨域处理及HTTPS问题处理

  1. 安装白名单服务
cordova plugin add cordova-plugin-whitelist

设置config.xml

  <allow-navigation href="http://*/*" />
  <allow-intent href="*" />
  <access origin="*" />

设置csp

"Content-Security-Policy" content="default-src *;style-src 'self' 'unsafe-inline';script-src http://192.10.200.105:8080 http://192.10.200.105 'unsafe-inline' 'self' 'unsafe-eval'">

使用GapDebug时,也要加入CSP,否则ios10可能会报错:

"Content-Security-Policy" content="default-src * data:cdvfile: gap: ;style-src 'self' 'unsafe-inline';script-src http://abc:8080 http://def.com 'self' 'unsafe-inline' 'unsafe-eval'">

代码请求:

            $http({
               url:'your url',
               method:"GET",
               cache:false
            }).then(function(response){
                console.log(response);
            },
            function(response){
                console.log(response);
            }
            );

实践当中遇到问题:
提示:

from cache caution:provisional headers are shown

解决方法是,删除whitelist重新安装

cordova plugin remove cordova-plugin-whitelist

HTTPS

在debug模式下,ionic会跳过证书的认证,这时候访问https是没有问题的。
如果发布release版本,则会对证书进行认证。

可以通过
https://www.sslshopper.com/ssl-checker.html
检查网站的证书是否安装正确。比如缺少 intermediate certificate 可能会无法正常访问https服务。

你可能感兴趣的:(App-Ionic)