我已将Cordova iOS应用升级到最新版本: iOS 4.1.0Cordova 6.0.0 我已经更新了插件并添加了新的WKWebView Engine插件. 我已将Content-Security-Policy添加到index.html文件中: meta http-equiv="Content-Security-Po
iOS 4.1.0 Cordova 6.0.0
我已经更新了插件并添加了新的WKWebView Engine插件.
我已将Content-Security-Policy添加到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">
我的config.xml始终包含:
<content src="index.html" /> <access origin="*" />
但我补充说
<access origin="*.mydomain.*" />
好的措施.
我控制了应用程序尝试连接的Web服务器,并且我已经启用了CORS:
<httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*" /> </customHeaders> </httpProtocol>
服务器具有有效的SSL证书,并且所有调用都是https://.
我在xCode中的plist有:
Allow Arbitrary Loads : Yes Exception Domains [mydomain] NSIncludesSubdomains : Yes NSTemporaryExceptionAllowsInsecureHTTPLoads : YES NSTemporaryExceptionMinimumTLSVersion : TLSv1.1
我正在构建应用程序并将其直接运行到设备上,并使用Safari Develop查看错误.
我有这个应用程序的Android版本,有自己更新的基本代码,工作正常.
我的进一步研究表明,这是导致问题的新WKWebView Engine插件.但我发现的唯一建议是在Ionic论坛中,我没有使用Ionic进行此构建.
只是为了确认,这些是我在调试中从Safari获得的错误消息:
[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.@jcesarmobile是对的.简单地将httpProtocol添加到我的web.config是不够的.我还必须将以下代码添加到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