Angular POST request causes 400
aliasav opened this issue · comments
aliasav commented
While registering a device with required parameters through angular, I get a 400 from the server.
var req = {
method: 'POST',
url: base_url,
headers: {
'Content-Type': 'application/json',
},
data: data,
}
$http(req).
then(function(response){
deferred.resolve(response);
}, function(data){
console.error(JSON.stringify(data));
deferred.reject();
});
This is the error response from the server:
{
"data":{},
"status":400,
"config":{"method":"POST","transformRequest":[null],"transformResponse": [null],"url":"http://192.168.0.103:8000/gcm/v1/device/register/","headers":{"Content-Type":"application/json","Accept":"application/json, text/plain, */*"},
"data":{"dev_id":"test","reg_id":"test","name":"Test"}},
"statusText":"BAD REQUEST"
}
A valid POST request is being sent from the client side, it is possible that the data is available in request.data rather than request,POST, in this case, it is probably causing an error in de-serailisation.
Adam Bogdał commented
Hi @aliasav. django-gcm
reads data from the request.body attribute.
Do you have the same error using curl
?
curl -X POST -H "Content-Type: application/json" -d '{"dev_id": "test", "reg_id":"test", "name":"Test"}' http://192.168.0.103:8000/gcm/v1/device/register/
aliasav commented
It works perfectly with curl, the error shows up while making a POST request through angular.