Ionic / angular get vs post post post 0 0 sometime

I am building an Ionic application with PHP REST API (Slim 3)

I use only POST requests. I am having HTTP errors when running on an iOS device:

   2016-06-02 12:34:01.143 connect-app[1987:1343510] {
  "data": null,
  "status": -1,
  "config": {
    "method": "POST",
    "transformRequest": [
      null
    ],
    "transformResponse": [
      null
    ],
    "url": "http://MYAPIWEBSITEURL/app-api-v3/get-new-orders",
    "headers": {
      "Accept": "application/json, text/plain, */*",
      "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJyaW5nMmJyaW5nLm5sIiwiaWF0IjoxNDY0ODIwMjgzLCJleHAiOjE3ODAzNTMwODMsImRhdGEiOnsidXNlcl9pZCI6IjEiLCJsb2NfaWQiOiIzNCIsImFwaSI6ImphNGYzZGM2MzJiNjlkZWM3MzA0MmMxZWU2NmNjMmYwIiwicm9sZSI6ImFkbWluIiwiZGVsY29tcF9pZCI6ZmFsc2V9fQ.TFAf-jSDOnKm0wHvPWuj8h5lumd1M6LAw87q-gPkcAs"
    }
  },
  "statusText": ""
}

The strange thing is that this happens only once. When I call the call again after an error, I get my data without errors.

This disappointed me, so I changed the method from POST to GET, and now I see that I no longer get a data error, I tried it like 200 times every time I get data.

I do not understand this behavior. In web browsing mode, all calls work, POST and GET. But on an iOS device, a POST request sometimes returns errors, and with GET it never returns an error

My service:

    this.setNewOrders = function () {
    $ionicLoading.show({ template: '<ion-spinner icon="ios"></ion-spinner><p style="margin: 5px 0 0 0;">Getting new orders..</p>'});
    newOrders = false;
    return $http({
        url: api_url + "/get-new-orders",
        method: 'GET',
        headers: {'Content-Type':'application/x-www-form-urlencoded'}
    }).then(function (response) {
        //console.log(response.data)
        if (response.data.status == 'success') {
            if (response.data.returnData.length > 0) {
                //set unixtime
                angular.forEach(response.data.returnData, function (value, key) {
                    //set time elapsed
                    var momentDate = moment(value.order_created);
                    value.dateMiliseconds = momentDate.unix() * 1000;
                });
                newOrders = response.data.returnData;
            }
        }
        $ionicLoading.hide();
        return response.data;
    });
}
+4
source share

All Articles