4

I am using an external api, which works very good in postman but not working when i call from angularjs.

Here is how i call from my angular js

$http.post('http://api.quickblox.com/users.json', {
    token: '2ba123a8c43664886c66702fb81b779b094cc7b8',
    'user[email]': email,
    'user[login]': email,
    'user[login]': email,
    'user[password]': password
}).then(function (results) {
    console.log('mid');
});

Here is preview of the image

It works good.

enter image description here

But it is not working when i do from angularjs call

Here is screenshot the response when i do angularjs call

enter image description here

dfsq
  • 191,768
  • 25
  • 236
  • 258
  • Compare the angular request with the one from postman. maybe you have to set an additional header or the **token** is not valid. – Michael Jul 04 '15 at 09:34
  • `token` is valid, i am additional header i am not sure,, so i try to do see the the postman's network, it has something strange.. –  Jul 04 '15 at 09:40

1 Answers1

1

Looks like you need to provide additional "Content-Type" header and reformat the data you are sending:

$http.post('http://api.quickblox.com/users.json', {
    token: '2ba123a8c43664886c66702fb81b779b094cc7b8',
    user: {
        email: email,
        login: email,
        password: password
    }
}, {
    'Content-Type': 'application/x-www-form-urlencoded'
})
.then(function(results) {
    console.log('mid');
})
.catch(function(response) {
    console.log('Error', response.status, response.data.errors);
});

Demo: http://plnkr.co/edit/ishIqko1GHT7IGvXV8ZF?p=preview

dfsq
  • 191,768
  • 25
  • 236
  • 258