apache/cordova

Cordova XMLHttpRequest cannot load

Closed this issue · 4 comments

Hello,

I have updated Cordova 10.0.0 also iOS@6.1.1, Using this config.xml changes

    '<preference name="scheme" value="app" />
    <preference name="hostname" value="www" `/>'

I can see my app view but not able call web api ( http request ), It is show in console error as below

Origin app://www is not allowed by Access-Control-Allow-Origin.

Please share if any solutions for this

Thank you
Screen Shot 2020-09-03 at 5 06 55 PM

The server must implement CORS headers.

Here are some resources that should help:

Since this isn't a bug with Cordova I'll be closing the issue. If you need further assistance, our slack is a great place to ask.

The server must implement CORS headers.

Here are some resources that should help:

Since this isn't a bug with Cordova I'll be closing the issue. If you need further assistance, our slack is a great place to ask.

Thank you reply

I am using IP address for access API, Is that allowed with this solution as you see in image

Yes. If you're using the file:// protocol, then you must use the wildcard * to allow any origin.

If you're using scheme, then you're origin with be <scheme>://<host> ie.... the default scheme settings cordova use is app://localhost.

If more than one client uses the same APIs (such as a website), then you'll need to implement backend logic that checks the Origin header and if acceptable, then set the response Access-Control-Allow-Origin header appropriately.

Hi, I am also running into this CORS issue, but my app downloads files from githubusercontent.com so I don't have control of the server. I tried the local fix by setting scheme and hostname in config.xml, but I'm still getting this "Access-Control-Allow-Origin" error. Is there a workaround in this case? Thank you!