简体   繁体   English

Access-Control-Allow-Origin不允许使用Origin null(从android获取XML)

[英]Origin null is not allowed by Access-Control-Allow-Origin (get XML from android)

I've researched about this problem. 我已经研究了这个问题。
Everywhere people get this error because of reading local file from localhost. 人们到处都会收到此错误,因为从本地主机读取本地文件。 Also almost everywhere people need a json. 几乎每个人都需要json。

In my case i want to get this xml file from this site from android (WebView). 以我为例,我想从android(WebView)网站上获取 xml文件。 So can anybody explain what's wrong? 有人能解释什么地方吗? What should I do to get it? 我应该怎么做才能得到它?

Here's my code: 这是我的代码:

$.get('http://www.revotech.am/smarthome/app/xml/config.xml', function(xmlData)
{
    ...
}

I assue you are using Android version JELLY_BEAN or above and the javascript is running in the context of a file schema - If YES then do the following. 我保证您使用的是Android版本JELLY_BEAN或更高版本,并且javascript在文件模式的上下文中运行-如果是,请执行以下操作。

webView.getSettings().setAllowFileAccessFromFileURLs(true); webView.getSettings()。setAllowFileAccessFromFileURLs(true);

From the Android documentation: 从Android文档中:

Sets whether JavaScript running in the context of a file scheme URL should be allowed to access content from any origin. 设置是否应允许在文件方案URL上下文中运行的JavaScript从任何来源访问内容。 This includes access to content from other file scheme URLs. 这包括从其他文件方案URL访问内容。 See setAllowFileAccessFromFileURLs(boolean). 请参见setAllowFileAccessFromFileURLs(boolean)。 To enable the most restrictive, and therefore secure policy, this setting should be disabled. 要启用限制性最强,因此最安全的策略,应禁用此设置。

The default value is true for API level ICE_CREAM_SANDWICH_MR1 and below, and false for API level JELLY_BEAN and above. 对于API级ICE_CREAM_SANDWICH_MR1及以下,默认值为true;对于API级JELLY_BEAN及以上,默认值为false。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android webview - XMLHttpRequest无法加载Origin <url> Access-Control-Allow-Origin不允许使用 - Android webview - XMLHttpRequest cannot load Origin <url> is not allowed by Access-Control-Allow-Origin android webview - 访问控制允许来源 - android webview - Access-Control-Allow-Origin JSON_2_Region.json。 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 因此,不允许访问原始“空”。 - JSON_2_Region.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. 在android web视图中,Access-Control-Allow-Origin.:1不允许使用null? - Origin null is not allowed by Access-Control-Allow-Origin.:1 in android web view? webview-访问控制允许原点不允许原点(使用cordova将angular转换为mobile) - webview - origin is not allowed by access-control-allow-origin (convert angular to mobile using cordova) Access-Control-Allow-Origin不允许在PhoneGap中使用ng-views获取Origin - using ng-views in PhoneGap getting Origin is not allowed by Access-Control-Allow-Origin Android 4.1上的Access-Control-Allow-Origin错误 - Access-Control-Allow-Origin Error At Android 4.1 WebView不存在“ Access-Control-Allow-Origin”标头[ANDROID] - WebView No 'Access-Control-Allow-Origin' header is present [ANDROID] 科尔多瓦没有访问控制允许来源 - cordova No Access-Control-Allow-Origin Angular 无“访问控制允许来源” - Angular No 'Access-Control-Allow-Origin'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM