执行cordova仿真时无法连接到服务器

时间:2015-11-13 18:07:51

标签: ibm-mobilefirst mobilefirst-server

我使用示例LDAP Login with LDAP Server将我的应用与LDAP连接。我可以将app示例与服务器连接起来。我也可以修改应用并连接。

问题是当我把mfp作为插件时,我把这个例子放在了适用于iOS的Cordova项目中。

我可以在_MobileBrowserSimulator中看到该应用程序,并且可以连接到服务器,但是当我执行mfp cordoba模拟应用程序时,请不要与服务器连接。

---更新---

我使用与LDAP相同的示例,但这在移动模拟器中运行,但在设备中不起作用。这是一个在模拟器中运行但不在设备中运行的简单示例。

main.js

function getSecretData(){
var request = new WLResourceRequest("/Random/getInteger",
        WLResourceRequest.GET);


request.send().then(onSuccess, onFailure);
}


function onSuccess(r) {
   document.getElementById('guille').innerHTML = r;
}

function onFailure(r) {
     document.getElementById('guille').innerHTML = r;
}

index.js

function wlCommonInit(){
    WL.App.setServerUrl("http://127.0.0.1:10080/MyMFPProject",success, fail);
    WL.Client.connect();
}

function success(r){
    document.getElementById('guille').innerHTML = r;
}

function fail(r){
    document.getElementById('guille').innerHTML = "error: " +r;
}

function onSuccess(r) {
 document.getElementById('guille').innerHTML = JSON.stringify(r);
}

function onFailure(r) {
 document.getElementById('guille').innerHTML = JSON.stringify(r);
}

1 个答案:

答案 0 :(得分:1)

更新:根据评论,听起来ATS仍然启用,请求确实会失败。通过将以下内容添加到应用程序的* -info.plist中来禁用ATS:

<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><true/>
</dict>

在此处阅读更多内容:https://developer.ibm.com/mobilefirstplatform/2015/09/09/ats-and-bitcode-in-ios9/

代码看起来很脆弱。
我会改变它,如下所示。如果它仍然失败,那么您需要创建失败的测试用例演示。听起来它也应该失败,没有任何与LDAP相关的东西......

function wlCommonInit(){
    WL.App.setServerUrl("http://127.0.0.1:10080/MyMFPProject",success, fail);

}

function success(r){
    document.getElementById('guille').innerHTML = r;
    WL.Client.connect({onSuccess: connectSuccess, onFailure: connectFailure);
}

function connectSuccess() {
    getSecretData();
    // ...
}

function connectFailure() {
    // handle connect failure
}

// the rest of the functions
相关问题