Ionic 3 Cordova ajax 调用在 Windows 10 (UWP) 上失败
我之前尝试过问这个,购买没有得到真正的答案,现在已经挣扎了一个多月.
I have attempted to ask this previously, buy got no real answers, and have now been struggling for over a month.
我只是无法让我的 ajax 调用在为 Windows 10 UWP 构建的 Ionic 3 Cordova 应用程序上工作.他们可以访问本地主机,但不能访问任何外部连接.
I just cannot get my ajax calls to work on an Ionic 3 Cordova application built for a Windows 10 UWP. They can access localhost, but not any outside connections.
该应用程序在 Android 和 iOS 上都能正常运行.
The application works fine on both Android and iOS.
我正在尝试在我的开发机器上进行本地测试.我使用证书(购买)签署应用程序,安装此证书,构建适用于 Windows 的应用程序,并且能够打开构建的 CordovaApp.Windows10_1.0.1.1_x86.appxupload
,然后加倍点击嵌入的CordovaApp.Windows10_1.0.1.1_x86.appx
文件进行安装,安装成功.安装表明该应用需要访问互联网.
I am trying to test this locally on my dev machine. I use a certificate (bought) to sign the application, install this certificate, build the application for Windows, and am able to open up the built CordovaApp.Windows10_1.0.1.1_x86.appxupload
, and then double click the embedded CordovaApp.Windows10_1.0.1.1_x86.appx
file to install, which completes successfully. The install indicates the app need internet access.
在 config.xml
中,我有以下标签,正如其他地方所建议的那样......
In the config.xml
, I have the following tags, as suggested elsewhere...
<allow-navigation href="*" />
<access origin="*" />
但是,当我运行时,http.get 调用只返回 0
而没有其他信息.我可以在 Visual Studio 中运行,查看返回的错误对象,除了这个 0
返回之外,没有得到更多信息.
However, when I run, the http.get call just returns 0
with no other information. I can run in Visual Studio, and look at the returned error object, and get no further info, apart from this 0
return.
我已经运行了 fiddler,按照 here 的说明启用了 https 解密,但我在响应标头中看到的只是
I have run fiddler, enabled the https decryption as explained here, but all I see in the response header is
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 13:44:21.686
Connection: close
主视图中的结果实际上显示了 200
,所以我认为这并没有向我展示任何真实的东西.
The result in the main view actually shows 200
, so I don't think this is showing me anything real.
我完全不知所措.我没有其他地方可以搜索.我可能会错过什么?
I am at a complete loss. I have no where else to search. What could I be missing?
当我在此处旁加载应用程序时,我是否应该能够在 Windows 10 机器上使用外部 ajax?我还没有从商店尝试过,因为在我知道它有效之前我不想上传.
Should I be able to use external ajax on a Windows 10 machine, when I have sideloaded the application as here? I haven't tried from the store yet, as I don't want to upload until I know it works.
非常欢迎任何建议.肯定有人让 Ionic 3 应用程序访问外部 ajax 工作?
Any suggestions desperately welcomed. Surely someone has had an Ionic 3 application accessing external ajax working?
提前感谢您的帮助
[更新 1]
如果我在同一台机器上运行应用程序,只使用 Ionic serve(所以它只是在浏览器中运行,而不是在 UWP 中托管),ajax 调用也可以正常工作.
If I run the application on the same machine, just using Ionic serve (so it just runs in the browser rather than hosted in the UWP), the ajax calls also work fine.
[更新 2]
我现在已经使用 Visual Studio 模板创建了一个 Cordova 应用程序,因此将所有其他框架排除在外.
I have now created a Cordova application using the Visual Studio template, so taking all other frameworks out of the equation.
我使用 vanilla JavaScript 来做我的休息调用...
I used vanilla JavaScript to do my rest call...
document.addEventListener('deviceready', callUrl, false);
function callUrl() {
console.log('callUrl');
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://myserveraddress.com/myapp/testroute');
xhr.send(null);
xhr.onreadystatechange = function () {
var DONE = 4; // readyState 4 means the request is done.
var OK = 200; // status 200 is a successful return.
if (xhr.readyState === DONE) {
if (xhr.status === OK)
console.log(xhr.responseText);
} else {
console.log('Error: ' + xhr.status);
}
}
};
我在调试器中运行它,甚至在这里我得到一个错误(状态代码为 0).
I run this in the debugger, and even here I get an error (status code of 0).
当我打开构建包并查看 cordova_plugins.js
文件时,我注意到的另一件事..
Another thing I noticed when I open up the build package and look at the cordova_plugins.js
file..
我的 Ionic 应用具有以下...
My Ionic app has the following...
cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [
{
"id": "cordova-plugin-console.logger",
"file": "plugins/cordova-plugin-console/www/logger.js",
"pluginId": "cordova-plugin-console",
"clobbers": [
"cordova.logger"
]
},
{
"id": "cordova-plugin-console.console",
"file": "plugins/cordova-plugin-console/www/console-via-logger.js",
"pluginId": "cordova-plugin-console",
"clobbers": [
"console"
]
},
{
"id": "cordova-plugin-device.device",
"file": "plugins/cordova-plugin-device/www/device.js",
"pluginId": "cordova-plugin-device",
"clobbers": [
"device"
]
},
{
"id": "cordova-plugin-device.DeviceProxy",
"file": "plugins/cordova-plugin-device/src/windows/DeviceProxy.js",
"pluginId": "cordova-plugin-device",
"merges": [
""
]
},
{
"id": "cordova-plugin-splashscreen.SplashScreen",
"file": "plugins/cordova-plugin-splashscreen/www/splashscreen.js",
"pluginId": "cordova-plugin-splashscreen",
"clobbers": [
"navigator.splashscreen"
]
},
{
"id": "cordova-plugin-splashscreen.SplashScreenProxy",
"file": "plugins/cordova-plugin-splashscreen/www/windows/SplashScreenProxy.js",
"pluginId": "cordova-plugin-splashscreen",
"runs": true
},
{
"id": "cordova-plugin-statusbar.statusbar",
"file": "plugins/cordova-plugin-statusbar/www/statusbar.js",
"pluginId": "cordova-plugin-statusbar",
"clobbers": [
"window.StatusBar"
]
},
{
"id": "cordova-plugin-statusbar.StatusBarProxy",
"file": "plugins/cordova-plugin-statusbar/src/windows/StatusBarProxy.js",
"pluginId": "cordova-plugin-statusbar",
"runs": true
},
{
"id": "ionic-plugin-keyboard.KeyboardProxy",
"file": "plugins/ionic-plugin-keyboard/src/windows/KeyboardProxy.js",
"pluginId": "ionic-plugin-keyboard",
"clobbers": [
"cordova.plugins.Keyboard"
],
"runs": true
}
];
module.exports.metadata =
// TOP OF METADATA
{
"cordova-plugin-console": "1.0.5",
"cordova-plugin-device": "1.1.4",
"cordova-plugin-splashscreen": "4.0.3",
"cordova-plugin-statusbar": "2.2.2",
"cordova-plugin-whitelist": "1.3.1",
"ionic-plugin-keyboard": "2.2.1"
};
// BOTTOM OF METADATA
});
现在,我注意到 module.exports.metadata
中的每个插件在 module.exports
中也有一个条目,除了 cordova-plugin-whitelist代码>!
Now, I notice every plugin in the module.exports.metadata
also has an entry in the module.exports
EXCEPT for cordova-plugin-whitelist
!
如果我为在 VS 中创建的 Corvoda 应用程序打开相同的文件,我会看到以下内容...
If I open the same file for the Corvoda application created in VS, I see the following...
cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [];
module.exports.metadata =
// TOP OF METADATA
{
"cordova-plugin-whitelist": "1.2.2"
};
// BOTTOM OF METADATA
});
所以这对于白名单插件也没有其他作用
So this has nothing else for the whitelist plugin as well
这里会不会少了什么?这个白名单插件会不会安装不正确?
Could there be something missing here?? Could this white-list plugin not be installed correctly?
推荐答案
我有类似的情况,我的 ajax 调用在 TEST 中运行良好,但是当我转移到 PROD 时,它们会失败.
I had a similar situation where my ajax calls worked fine in TEST, but when I moved to PROD, they would fail.
最终在我试图访问的服务器上找到了一个缺少中间证书的答案.TEST 有证书,PROD 没有.
The answer was finally tracked down as a missing intermediary certificate on the server I was trying to access. TEST had the cert, PROD did not.
我希望这会有所帮助.
相关文章