django-gcm icon indicating copy to clipboard operation
django-gcm copied to clipboard

Angular POST request causes 400

Open aliasav opened this issue 9 years ago • 2 comments

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.

aliasav avatar Oct 19 '15 09:10 aliasav

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/

bogdal avatar Oct 19 '15 12:10 bogdal

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

aliasav avatar Oct 19 '15 12:10 aliasav