ionic app cannot connect cors enabled server with $http

后端 未结 2 1769
-上瘾入骨i
-上瘾入骨i 2020-12-01 18:50

I am trying to build a mobile app with ionic framework. When my application tries to connect server to get json ( server is web api and cors is enabled) it just returns 40

相关标签:
2条回答
  • 2020-12-01 19:13

    you can just go into config .xml file and edit this line

    <access origin="*://*/*" />
    

    and you can call any data with out intruption of CORS in console thank you plz apply this code your ionic app

    0 讨论(0)
  • 2020-12-01 19:14

    cordova-plugin-whitelist seems to be "mandatory" at present.

    install it :

    cordova plugin add cordova-plugin-whitelist
    

    configure config.xml

    You can keep your current setup with * or change for more restrictive rules

    add a html policy on index.html, you shall add a Policy also. To authorise everything, here it is :

     <meta http-equiv="Content-Security-Policy" content="default-src *;
     style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline'
     'unsafe-eval'"
    
    0 讨论(0)
提交回复
热议问题