Cors + Cordova : Issues With : Access-control-allow-origin
Solution 1:
You need the Cordova whitelist plugin: https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/.
Have this in config.xml:
<accessorigin="*" /><allow-navigationhref="*"/>
And have the Content-Security-Policy meta in index.html. Something like:
<metahttp-equiv="Content-Security-Policy"content="default-src *; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data:">
Solution 2:
If the Cordova Whitelist plugin doesn't work out for you, you can use the Cordova advanced Http plugin to make calls to external servers.
Install using: cordova plugin add cordova-plugin-advanced-http
Link to plugin: https://github.com/silkimen/cordova-plugin-advanced-http?ref=hackernoon.com
Solution 3:
If you just experienced the issue starting Aug 1 2019. This Access-Control-Allow-Origin Error..(using cordova) might be related to the problem.
Solution 4:
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
Solution 5:
I found the solution for my similar scenario, was getting the error: "access-control-allow-origin cannot contain more than one origin"
Eventually I found that although I had set my .net core API to allow all sources like so:
public voidConfigureServices(IServiceCollection services)
{
services.AddCors();
...
public voidConfigure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseCors(builder => builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
...
I had then left an old CORS command in the web.config file in the website root of the API:
<customHeaders>
<addname="Access-Control-Allow-Origin"value="https://localhost:444" />
</customHeaders>
I commented out the customHeaders section and it worked.
Mission accomplished!
Post a Comment for "Cors + Cordova : Issues With : Access-control-allow-origin"