Android 上混合应用程序的 MobileFirst 服务器连接错误
MobileFirst server connect error for hybrid app on Android
我正在使用 MobileFirst 开发混合应用程序,它使用 HTTP 适配器连接到 REST 服务。我在 firefox 或任何其他浏览器中的预览没有错误,应用程序运行良好。
如果我将应用程序部署到我的 Samsung Galaxy S4 mini。我收到以下错误,应用程序未连接到服务器。
klasserrorCode: "UNEXPECTED_ERROR"errorMsg: "Unexpected errorCode occurred. Please try again."invocationContext: nullresponseHeaders: Object__proto__: ObjectresponseText: ""status: 0__proto__: klassconstructor: function klass() {errorCode: nullerrorMsg: nullgetAllHeaders: function () {getHeader: function (name) {getHeaderNames: function () {initialize: function (transport, invocationContext) {invocationContext: nullresponseJSON: ""responseText: ""status: -1__proto__: Object main.js:160
互联网使用权限设置在`AndroidManifest.xml
我的适配器代码(功能之一):
function getCommonInformation() {
var path = "users/common/information";
var input = {
method : 'get',
returnedContentType : 'json',
path : path,
};
return WL.Server.invokeHttp(input);
}
在适配器的应用程序中调用:
var resourceRequest = new WLResourceRequest("/adapters/RESTAdapter/getCommonInformation", WLResourceRequest.GET);
resourceRequest.send().then(function(result) {
dataStore.common = JSON.parse(result.responseText);
}, onFailure);
您面临的问题是您的应用仍配置为连接到 http://localhost:10080/
请按照以下步骤将您的 IP 更改为计算机的 IP/Host
- 右键单击
apps
文件夹内的应用程序文件夹:右键单击 > 构建设置并部署目标...
- 选中构建应用程序以使用不同的 MobileFirst 服务器框
- 输入你的机器IP地址、端口号(10080)、上下文(通常是项目名称)
http://YOUR_MACHINE_IP:10080/YOUR_PROJECT_NAME
- 重建应用程序
如果您使用的是 MobileFirst studio 中的内置服务器,请确保您的 phone 和 MobileFirst 服务器(您的计算机)在同一网络上,并且您的计算机上的端口 10080 未被阻止。
我正在使用 MobileFirst 开发混合应用程序,它使用 HTTP 适配器连接到 REST 服务。我在 firefox 或任何其他浏览器中的预览没有错误,应用程序运行良好。
如果我将应用程序部署到我的 Samsung Galaxy S4 mini。我收到以下错误,应用程序未连接到服务器。
klasserrorCode: "UNEXPECTED_ERROR"errorMsg: "Unexpected errorCode occurred. Please try again."invocationContext: nullresponseHeaders: Object__proto__: ObjectresponseText: ""status: 0__proto__: klassconstructor: function klass() {errorCode: nullerrorMsg: nullgetAllHeaders: function () {getHeader: function (name) {getHeaderNames: function () {initialize: function (transport, invocationContext) {invocationContext: nullresponseJSON: ""responseText: ""status: -1__proto__: Object main.js:160
互联网使用权限设置在`AndroidManifest.xml
我的适配器代码(功能之一):
function getCommonInformation() {
var path = "users/common/information";
var input = {
method : 'get',
returnedContentType : 'json',
path : path,
};
return WL.Server.invokeHttp(input);
}
在适配器的应用程序中调用:
var resourceRequest = new WLResourceRequest("/adapters/RESTAdapter/getCommonInformation", WLResourceRequest.GET);
resourceRequest.send().then(function(result) {
dataStore.common = JSON.parse(result.responseText);
}, onFailure);
您面临的问题是您的应用仍配置为连接到 http://localhost:10080/
请按照以下步骤将您的 IP 更改为计算机的 IP/Host
- 右键单击
apps
文件夹内的应用程序文件夹:右键单击 > 构建设置并部署目标... - 选中构建应用程序以使用不同的 MobileFirst 服务器框
- 输入你的机器IP地址、端口号(10080)、上下文(通常是项目名称)
http://YOUR_MACHINE_IP:10080/YOUR_PROJECT_NAME
- 重建应用程序
如果您使用的是 MobileFirst studio 中的内置服务器,请确保您的 phone 和 MobileFirst 服务器(您的计算机)在同一网络上,并且您的计算机上的端口 10080 未被阻止。