从3.7.0到4.0.2跨域XHR 404的PhoneGap Android [英] PhoneGap Android from 3.7.0 to 4.0.2 cross-domain XHR 404's
问题描述
我在 config.xml
中具有以下Android应用程序:
I have an Android application with the following in config.xml
:
<access origin="*" />
然后,我开始使用Angular $向API端点请求http
像这样:
Then, I begin a request to an API end-point using Angular $http
like this:
$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 Build设置< preference name = phonegap-version value = cli-5.1.1 / >
根据 http: //phonegap.com/blog/2015/06/16/phonegap-updated-on-build/ ),则 catch
用<$ c调用$ c> 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.
是什么原因引起的?我在变更日志中看不到任何相关条目( https://github.com。 com / apache / cordova-android / 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
版本的Android。正如@laughingpine在评论中指出的那样,白名单机制已更改。以前,您可以使用< access origin = * />
来访问所有域。
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.
现在您需要 cordova-plugin-whitelist
( https://github.com/apache/cordova-plugin-whitelist )。有关详细信息,请参阅文档。较早的通配符大致等同于< allow-navigation href = * />
,这是新机制。
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 Build下进行构建(此后称为PGB),则需要添加插件。由于该插件在 npm
(节点软件包管理器)下可用,因此您可以在 cordova-plugin-whitelist $ c下找到最新版本。 $ c>名称( https://www.npmjs.com/package/cordova-plugin-白名单)。 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.
这篇关于从3.7.0到4.0.2跨域XHR 404的PhoneGap Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!