My postman request is working fine, but the equivalent in angularJS isn't.
I'm able to get the response I need in Postman, but for some reason, it's not working in Angular.
var settings = {
"async": true,
"crossDomain": true,
"url": "http://197.157.93.110/Apiv1/token",
"method": "POST",
"headers": {
"cache-control": "no-cache",
"postman-token": "c76c4b6a-9a69-23dd-0171-8e6cbacd7944",
"content-type": "application/x-www-form-urlencoded"
},
"data": {
"grant_type": "password",
"UserName": "user1",
"Password": "password"
}
}
$.ajax(settings).done(function (response) {
console.log(response);
});
This is what my Angular code looks like:
services.factory('documentService', ['$http', function($http){
return {
getToken:function(grant_type,user,password){
return $http({
method:"POST",
url:"http://197.156.93.110/Apiv1/token",
headers: {
"cache-control": "no-cache",
"content-type": "application/x-www-form-urlencoded"
},
data: {
"grant_type": grant_type,
"UserName": user,
"Password": password
}
});
}
,
When I try to use this, I keep getting a Bad Request error with a code of 400.
I'm trying to call the promise later in my code like this:
documentService.getToken("password","user1","password").success(function(token){
$scope.access_token=token.access_token;
$scope.userName=token.userName;
$scope.token_type=token.token_type;
$scope.message={"message":"success"};
$interval(function () {
$scope.message = "";
}, 10000);
//call get documents if only access token is success
}).error(function(err){
$scope.message=err;
$interval(function () {
$scope.message = "";
}, 10000);
});