Post not working properly in angularjs

I use an external api that works very well in the postman, but does not work when I call from angularjs.

This 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 a preview image

It works well.

enter image description here

But it does not work when I make an angularjs call

Here is a screenshot of the answer when I call angularjs call

enter image description here

+4
source share
1 answer

It looks like you need to provide an optional Content-Type header and reformat the data sent:

$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

+1
source

All Articles