我正在开发一个离子项目来创建 android 和 ios 应用程序。我是 ionic 新手,需要帮助来了解如何通过托管在我的服务器上的 restful 服务进行登录。
restful 对每个POST
或PUT
请求使用此身份验证:
username: admin
pass: 123123
所以我正在测试一个POST
请求。我不知道如何进行身份验证。服务器端已设置并正在运行。并且api已经过测试,没有错误。(使用可可restclient测试)
好的。这是我的 app.js
angular.module('tapp', ['ionic'])
.config(function($stateProvider, $urlRouterProvider){
$stateProvider
.state('testapp', {
url: "/tapp",
abstract: true,
templateUrl: "template/menu.html",
controller: 'MenuCtrl'
})
.state('tapp.home', {
url: '/home',
views: {
'tappMenu': {
templateUrl: 'template/home.html',
controller: 'HomeCtrl'
}
}
})
.state('tapp.dash', {
url: '/dash',
views: {
'tappMenu': {
templateUrl: 'template/dash.html',
controller: 'DashCtrl'
}
}
})
$urlRouterProvider.otherwise('/tapp/home');
这是我的控制器:
.controller('HomeCtrl', function($scope, $http){
$scope.formData = [] // just testing post data
$scope.submit = function(){
var data = $scope.formData.push($scope.inputData);
$http.post('http://localhost/tapp-server/posted', data);
};
}
我的 php 函数(使用 codeigniter 休息服务器)
public function posted_post()
{
$this->response(json_encode($_POST), 200);
}
这里的问题是,每当应用程序将数据发布到 php 时,我不知道如何应用基本的 restful 身份验证,因为每当它发布数据时,我都会收到“未授权”错误。
对于其他数据,例如使用 获取数据GET
,我接收数据并完美处理。只有在这POST
部分我很困惑。