问题
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.
But it is not working when i do from angularjs call
Here is screenshot the response when i do angularjs call
回答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
来源:https://stackoverflow.com/questions/31218982/post-not-working-as-expected-in-angularjs