Hello. Please your kind help. I'm coding a ionic client for Traccar and having problem for post a session.
This is my code:
var login = function(user) {
var uemail = user.name;
var upassword = user.password;
var post_data = {"email":uemail,"password":upassword};
console.log(post_data);
return $q(function(resolve, reject) {
$http({
url: API_ENDPOINT.url + '/session',
method: 'POST',
headers: {"content-type": "application/x-www-form-urlencoded"},
data: post_data
}).then(function(result) {
if (result.data.success) {
storeUserCredentials(result.data.token);
resolve(result.data.msg);
} else {
reject(result.data.msg);
}
});
});
};
Which gives me a 401 Unauthorized error, as you could see on capture:
https://www.dropbox.com/s/u0ftcetom4qn8ib/auth-error.png?dl=0
Please note I'm loggin post-data values which actually are: {email: "admin", password: "admin"}
Using postman I can post without error (and off course using same post-data values), as you could see on capture:
https://www.dropbox.com/s/gg2fgk5o87cab5j/postman-ok.png?dl=0
What am I missing?
Any help will be very appreciated. Best regards!
Have you checked actual network request?
Hello. I checked the actual network request and found the problem:
It was sending: {"email":"admin","password":"admin"} (json format), while: email=admin&password=admin (url encoded) was required.
Thanks a lot.
Hello. Please your kind help. I'm coding a ionic client for Traccar and having problem for post a session.
This is my code:
Which gives me a 401 Unauthorized error, as you could see on capture:
https://www.dropbox.com/s/u0ftcetom4qn8ib/auth-error.png?dl=0
Please note I'm loggin post-data values which actually are: {email: "admin", password: "admin"}
Using postman I can post without error (and off course using same post-data values), as you could see on capture:
https://www.dropbox.com/s/gg2fgk5o87cab5j/postman-ok.png?dl=0
What am I missing?
Any help will be very appreciated. Best regards!