Cordoba iOS Error: Initial null value not allowed Access-Control-Allow-Origin

I have updated the ICOS application from Cordoba to the latest versions:

iOS 4.1.0 Cordova 6.0.0 

And I updated the plugins and also added a new WKWebView Engine plugin.

I added a Content-Security-Policy file index.html:

 <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' 'unsafe-inline' data:;connect-src 'self' https://mydomain/myservice/; plugin-types application/pdf"> 

My config.xml always contain:

 <content src="index.html" /> <access origin="*" /> 

but i added

 <access origin="*.mydomain.*" /> 

for good measure.

I run a web server to which the application is trying to connect, and I included it CORS:

 <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*" /> </customHeaders> </httpProtocol> -Allow-Origin" value = "*" /> <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*" /> </customHeaders> </httpProtocol> 

The server has a valid SSL certificate, and all of its challenges: https: //.

My plist in xCode has:

 Allow Arbitrary Loads : Yes Exception Domains [mydomain] NSIncludesSubdomains : Yes NSTemporaryExceptionAllowsInsecureHTTPLoads : YES NSTemporaryExceptionMinimumTLSVersion : TLSv1.1 

I create and run the application directly on the device and use Safari Develop to view the error.

I have an Android version of this application with my own updated base code that works fine.

My further research revealed that this is the new WKWebView Engine plugin that is causing the problem. But the only suggestions I found about this are in the Ionic forums, and I don't use Ionic for this build.

Just for confirmation, these are the error messages I get from Safari when debugging:

 [Error] Failed to load resource: the server responded with a status of 405 (Method Not Allowed) ([my thing], line 0) [Error] Failed to load resource: Origin null is not allowed by Access-Control-Allow-Origin. ([my thing], line 0) [Error] XMLHttpRequest cannot load https://[mydomain]/[my service]/[my thing]. Origin null is not allowed by Access-Control-Allow-Origin. the server responded with a status of [Error] Failed to load resource: the server responded with a status of 405 (Method Not Allowed) ([my thing], line 0) [Error] Failed to load resource: Origin null is not allowed by Access-Control-Allow-Origin. ([my thing], line 0) [Error] XMLHttpRequest cannot load https://[mydomain]/[my service]/[my thing]. Origin null is not allowed by Access-Control-Allow-Origin. thing], line [Error] Failed to load resource: the server responded with a status of 405 (Method Not Allowed) ([my thing], line 0) [Error] Failed to load resource: Origin null is not allowed by Access-Control-Allow-Origin. ([my thing], line 0) [Error] XMLHttpRequest cannot load https://[mydomain]/[my service]/[my thing]. Origin null is not allowed by Access-Control-Allow-Origin. 
+6
source share
1 answer

@jcesarmobile was correct. Just add httpProtocol in my web.config was not enough. I also had to add the following code in global.asax Application_BeginRequest :

 HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*") If HttpContext.Current.Request.HttpMethod.Equals("OPTIONS") Then HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "POST, PUT, DELETE") HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept") HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000") HttpContext.Current.Response.End() End If 
+1
source

All Articles