【发布时间】:2018-03-12 15:25:40
【问题描述】:
我正在开发一个 ionic 项目以创建 android 和 ios 应用程序。 我是 ionic 新手,需要帮助了解如何通过托管在我的服务器上的 restful 服务进行登录。
restful 对每个 POST 或 PUT 请求使用此身份验证:
username: admin
pass: 123123
所以我正在测试POST 请求。我不知道如何进行身份验证。
服务器端已设置并正在运行。并且api已经过测试,没有错误。 (使用 cocoa 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 rest server)
public function posted_post()
{
$this->response(json_encode($_POST), 200);
}
这里的问题是,每当应用程序将数据发布到 php 时,我不知道如何应用基本的 RESTful 身份验证,因为每当它发布数据时,我都会收到“未授权”错误。
对于其他数据,例如使用GET 获取数据,我接收数据并完美处理。仅在此POST 部分我感到困惑。
【问题讨论】:
标签: rest cordova ionic-framework angularjs-http