bogdal / django-gcm

Google Cloud Messaging Server in Django
https://django-gcm.readthedocs.org
BSD 2-Clause "Simplified" License
98 stars 42 forks source link

Angular POST request causes 400 #38

Open aliasav opened 8 years ago

aliasav commented 8 years ago

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.

bogdal commented 8 years ago

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 8 years ago

It works perfectly with curl, the error shows up while making a POST request through angular.