PhoneGap的Andr​​oid版从3.7.0到4.0.2跨域XHR 404的 [英] PhoneGap Android from 3.7.0 to 4.0.2 cross-domain XHR 404's

查看:215
本文介绍了PhoneGap的Andr​​oid版从3.7.0到4.0.2跨域XHR 404的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在以下一个Android应用程序 config.xml中

I have an Android application with the following in config.xml:

<access origin="*" />

然后,我开始使用角到API端点的请求 $ HTTP 是这样的:

$http({
  data: this._createTokenRequest(tenant, username, password),
  method: 'POST',
  headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
  timeout: 10000,
  url: url + '/api/RequestToken'
}).catch(err => {
  alert(err.message || err);
  alert(JSON.stringify(err));
}).then(response => {
  alert(response);
});

3.7.0 响应处理程序将被调用。由于升级到 4.0.2 (使用PhoneGap的建立设置&LT; preference NAME =PhoneGap的版本值=CLI-5.1。 1/&GT; 作为根据的 http://phonegap.com/blog/2015/06/16/phonegap-updated-on-build/ ),在被调用了 404未找​​到错误。

In 3.7.0 the response handler will be invoked. Since upgrading to 4.0.2 (using PhoneGap Build setting <preference name="phonegap-version" value="cli-5.1.1" /> as according to http://phonegap.com/blog/2015/06/16/phonegap-updated-on-build/), the catch is invoked with a 404 Not Found error.

什么可能造成的?我看到的changelog( HTTPS没有相关的条目:// github上。 COM /阿帕奇/科尔多瓦-的Andr​​oid / BLOB / 4.0.2 / RELEASENOTES.md )。

What could have caused this? I see no relevant entry in the changelog (https://github.com/apache/cordova-android/blob/4.0.2/RELEASENOTES.md).

推荐答案

当您切换到 CLI-5.1.1 ,你会切换到 4.0.x的版本的Andr​​oid。正如@laughingpine已评论指出的,白名单机制已被更改。此前,你可以使用&LT;获得原产=*/&GT; 来获得对所有域。这不再适用。

When you switch to cli-5.1.1, you will switch to the 4.0.x version of Android. As @laughingpine has pointed out in a comment, the white-listing mechanism has been changed. Earlier, you could use <access origin="*" /> to obtain access to all domains. This no longer applies.

现在你需要科尔多瓦-插件白名单(<一个href=\"https://github.com/apache/cordova-plugin-whitelist\">https://github.com/apache/cordova-plugin-whitelist).请参阅文档的细节较早通配符大致相当于为&LT;允许导航HREF =*/&GT; ,这是新机制。

Now you need cordova-plugin-whitelist (https://github.com/apache/cordova-plugin-whitelist). Please refer to the documentation for the specifics. The rough equivalent of the earlier wildcard is <allow-navigation href="*" />, which is the new mechanism.

要建立的PhoneGap构建下的(因此提出被称为PGB),您将需要添加的插件。由于该插件在 NPM 可用(节点包管理器),你可以找到在科尔多瓦-插件白名单名(<一个href=\"https://www.npmjs.com/package/cordova-plugin-whitelist\">https://www.npmjs.com/package/cordova-plugin-whitelist). PGB可以建立从 NPM 插件具有以下符号:

To build under PhoneGap Build (hence forth referred to as PGB), you will need to add the plugin. Since the plugin is available under npm (the Node Package Manager), you can find the latest version under the cordova-plugin-whitelist name (https://www.npmjs.com/package/cordova-plugin-whitelist). PGB can build a plugin from npm with the following notation:

<gap:plugin name="cordova-plugin-whitelist" version="1.0.0" source="npm" />

现在PGB将正确建立和白名单和以前一样。

Now PGB will build correctly and your whitelist works as before.

这篇关于PhoneGap的Andr​​oid版从3.7.0到4.0.2跨域XHR 404的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆