HTTP POST blocked in Android, works perfectly with iOS - why?


#1

Hi, I have the following code for HTTP POST in my angular App. The reason I am using URL encode is to convert this into a simple HTTP POST (otherwise its converted to OPTIONS).

This code works perfectly on iOS but on Android devices, the POST is simply discarded (no error) - my server does not even receive it. Can someone help me understand why?

 var req = $http({
        method: 'POST',
        timeout: 10000,
        url: loginData.url + 'zm/index.php',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Accept': '*/*',
        },
        transformRequest: function (obj) {
            var str = [];
            for (var p in obj)
                str.push(encodeURIComponent(p) + "=" +
                    encodeURIComponent(obj[p]));
            var foo = str.join("&");
            console.log("****RETURNING " + foo);
            return foo;
        },

        data: {
            view: "request",
            request: "stream",
            connkey: $scope.connKey,
            command: cmd,
            user: loginData.username,
            pass: loginData.password
        }
    });
    req.success(function (resp) {

        console.log("SUCCESS: " + JSON.stringify(resp));
        var str = toast_blurb + "event:" + resp.status.event;
        console.log(str);
        $ionicLoading.hide();
        $ionicLoading.show({
            template: str,
            noBackdrop: true,
            duration: 2000
        });
    });

    req.error(function (resp) {
        console.log("ERROR: " + JSON.stringify(resp));
    });
}

#2

using android cordova 4.0.0? i.e. crosswalk?
then see Crosswalk and $http doesnt work


#3

claw, I am using Cordova 5 + crosswalk. HTTP works fine - just not POST and only for android. BTW, the problem was not that it is brittle in Android - I found later only POST requests were not going through at all from the phone to my server


#4

My apologies – it was an input error - the URL that was being formed for POST was invalid (iOS devices had the right input). Fixed