与IONIC合作我正在尝试调用简单的登录网络服务,但无法从IONIC代码传递服务所需的标头和正文参数。
网络服务的curl请求:
curl -v -H "Accept: application/json" -H "Content-Type:application/json" -H "ModifiedOn:0" -H "username:vikash|214057357158656" -H "password:gbadmin" -d '{"username":"vikash|214057357158656","password":"gbadmin"}' http://localhost:8282/services/Login3.0
响应:
{"ResponseJSON":{"Body":{"Datalist":{"Authentication":"true"}}}}
我的IONIC代码:
$scope.login = function() {
$http.post("http://redmine.youtility.in:8282/services/Login3.0", {"username":"vikash|214057357158656","password":"gbadmin"},"Accept: application/json" -H "Content-Type:application/json" -H "ModifiedOn:0" -H "username:vikash|214057357158656" -H "password:gbadmin");
如何传递IONIC代码中的参数并从Web服务获得响应。
答案 0 :(得分:3)
看一下这里,我已经为您提供了一个样本后期方法。
var userDetails = {
"username":"vikash|214057357158656",
"password":"gbadmin"
}
$scope.login = function() {
$http.post("http://redmine.youtility.in:8282/services/Login3.0",userDetails)
.success (function(response){
console.log(response);
}
.error(function(response){
console.log(response);
};
}
有关详细信息,请查看$http这个有角度的网站。