Can't perform POST request in Android browser

2019-03-02 12:41发布

问题:

I've got a angular application that displays records, and gives the user the ability to add records.

Everything works perfect on desktop or iOS devices, but on android devices, the POST method fails(403 - forbidden).

this is the code in my service:

obj.getRecords = function() {
    return $http.get(serviceBase + 'records');
};
obj.getRecord = function(id) {
    return $http.get(serviceBase + 'record/' + id);
};
obj.saveRecord = function(record) {
    return $http.post(serviceBase + 'record', record);
};

Anyone experienced with this problem?

回答1:

$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";

might fix your problem.

Reference: Angular docs



回答2:

I could imagine that it could have to do with an apple touch icon that is integrated into your site. I had it once that it missing (even if iPhones worked!) caused redirection to another site with another session id. This also caused a 403. It's just an idea though. It seems that the Android browser has some other way of retrieving the touch icon which is the error's cause.