CORS + Cordova : issues with : Access-Control-Allow-Origin

前端 未结 4 495
轻奢々
轻奢々 2020-12-08 15:18

I have been searching hours on this issue, but I still can\'t find any solution to this.

I am developping an App cordova (basicely HTML / JS) So : the app runs on mob

相关标签:
4条回答
  • 2020-12-08 15:59

    I have added following in nodejs server which solves my issue;

    app.use(function(req, res, next) {
        res.header("Access-Control-Allow-Origin", "*");
        res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
        next();
    });
    

    This may be helpful if you are using nodejs.

    Thanks

    0 讨论(0)
  • 2020-12-08 16:03

    If you just experienced the issue starting Aug 1 2019. This Access-Control-Allow-Origin Error..(using cordova) might be related to the problem.

    0 讨论(0)
  • 2020-12-08 16:09

    You need the Cordova whitelist plugin: https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/.

    Have this in config.xml:

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

    And have the Content-Security-Policy meta in index.html. Something like:

    <meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data:">
    
    0 讨论(0)
  • 2020-12-08 16:16

    There is no need to do such thing

    You just try to change the permission

    <?xml version="1.0" encoding="utf-8"?>
    <manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        ...
        android:usesCleartextTraffic="true"
        ...>
        ...
    </application>
    

    0 讨论(0)
提交回复
热议问题