phoneGap/Angular http 请求 404 错误在手机上,而在浏览器上正常



我在从我的网站读取网络服务时有角度的应用程序,它在浏览器上运行良好,但在 android 上无法正常工作。
我已经通过 build.phonegap.com/apps 构建了apk

在手机上,它给出以下错误

{"data":"","status":404,"config":
{"method":"GET","transformRequest":[null],
"transformResponse":[null],"async":true,
"url":"http://sub.example.com/api/items/1",
"headers":{"Accept":"application/json, text/plain, */*"}
},
"statusText":"Not Found"}    

我的 HTTP 请求代码是

$http({
async : true,
url: $scope.server+'/api/items/'+id,
method: "GET",
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).then(function(response) {
$scope.items = response.data;            
},function myError(response) {
$scope.error = response;
});

在手机上,它是对正确URL的请求,我已经从错误消息中复制了URL,并在手机上的chrome上检查了它,它正在打开。

我还添加了config.xml到根文件夹,它更改了应用程序标题,图标等,但仍然无法正常工作

<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns   = "http://www.w3.org/ns/widgets"
xmlns:gap   = "http://phonegap.com/ns/1.0"
id          = "com.example.sub"
versionCode = "1" 
version     = "1.0.0" >
<!-- versionCode is Android only -->
<!-- version is in major.minor.patch format --> 
<name>my app</name>
<description>
A simple app
</description>
<author href="https://example.com" email="email@gmail.com">
Fakhr-e-Alam
</author>
<access uri="http://*.example.com/" />

<platform name="android">
<icon src="icon.png" density="ldpi" />
</platform>
</widget>

我认为您需要将网络访问权限添加到config.xml中。

我在stackoverflow上发现了这个:android中的phonegap构建权限

相关内容

最新更新