我有一个端点[http://localhost:8080/cagb-api/api/merchants/asobancaria/accounts],它接收授权标题:
授权:持票人eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ
但它不需要额外的参数,所以我创建了一个Angular服务:
"use strict";
app.factory('accountsService', accountsService);
function accountsService($localStorage, $resource, SECURE_CONSTANTS){
var getAsobancariaAccountsRestService = $resource('http://localhost:8080/cagb-api/api/merchants/asobancaria/accounts', {},
{
getAsobancaria: {
method: 'GET',
headers: {
'Content-Type': 'application/json' ,
'Authorization': 'Bearer ' + $localStorage.token
},
transformRequest: function(data, headersGetter) {
headersGetter = {
'Accept': 'application/json'
};
data = JSON.stringify(data);
return data;
}
}
});
return {
/** Loads the all Asobancaria Accounts for an Account */
getAsobancariaAccounts : function(successCallback, errorCallback) {
getAsobancariaAccountsRestService.getAsobancaria({},
function(data){
successCallback(data);
}, function(error){
errorCallback(error.data);
});
},
};
}
在控制器中,我在这里称呼它:
"use strict";
app.controller('technicalConfigurationController', technicalConfigurationController);
function technicalConfigurationController($scope, $translate, accountsService) {
var successCallback = function (result) {
console.log(result);
};
var errorCallback = function (result) {
if (result.errorMessage !== undefined) {
$scope.message = $translate.instant(result.errorMessage);
} else {
$scope.message = $translate.instant('DEFAULT_APP_ERROR');
}
};
$scope.getAsobancariaAccounts = function(){
accountsService.getAsobancariaAccounts(successCallback, errorCallback);
};
}
但是当我使用按钮<input class="btn btn-success" type="submit" value="update" ng-click="updateAsobancariaAccounts()">
来调用服务时出现此错误:Error: $resource:badcfg
Response does not match configured parameter
我有其他[POST]服务以相同的方式制作但接收来自resquest的参数:
var createAsobancariaAccountRestService = $resource(SECURE_CONSTANTS.SECURE_API_HOST + SECURE_CONSTANTS.SECURE_API_ENDPOINTS.MERCHANTS + SECURE_CONSTANTS.SECURE_API_RESOURCES.ASOBANCARIA_ACCOUNTS, {
accountName: '@accountName',
accountNumber: '@accountNumber',
accountType: '@accountType',
bankId: '@bankId',
paymentMethodMain: '@paymentMethodMain',
lastUpdateSession: '@lastUpdateSession',
lastUpdateUser: '@lastUpdateUser'
}, {
create: {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + $localStorage.token
},
transformRequest: function(data, headersGetter) {
headersGetter = {
'Accept': 'application/json'
};
data = JSON.stringify(data);
return data;
}
}
});
return {
createAsobancariaAccount: function(asobancariaAccount, successCallback, errorCallback) {
createAsobancariaAccountRestService.create({
accountName: asobancariaAccount.accountName,
accountNumber: asobancariaAccount.accountNumber,
accountType: asobancariaAccount.accountType,
bankId: asobancariaAccount.bankId,
paymentMethodMain: asobancariaAccount.paymentMethodMain,
lastUpdateSession: asobancariaAccount.lastUpdateSession,
lastUpdateUser: asobancariaAccount.lastUpdateUser
}, function(data){
successCallback(data);
}, function(error){
errorCallback(error.data);
});
}
};