When submitting a POST request using the HTTPClient for user's authentification in my android app version, i got an error :
TiHTTPClient: (java.net.ProtocolException): exceeded content-length limit of 439 bytes
this is the request code :
var xhr = Titanium.Network.createHTTPClient({
onload : function(e) {
try {
var json_result = JSON.parse(this.responseText);
Ti.API.warn("json_result: " + JSON.stringify(json_result));
if (json_result.Status == 200) {
Ti.App.Properties.setBool('loggedIn', true);
Ti.App.Properties.removeProperty("catalgSyncDate");
Ti.App.Properties.setString("Token", json_result.Model.Token);
Ti.App.Properties.setObject("Model", json_result.Model);
Ti.App.Properties.setString("authenticationMessage", this.responseText);
Ti.App.Properties.setObject("usrobj", user);
getUserProfile(json_result.Model.UserId);
getTrainingAcquis(json_result.Model.UserId);
CheckAuthentication();
//Alloy.createController('monCompte').getView().open();
//$.loginWin.close();
} else {
$.actInd.hide();
$.actIndContainer.hide();
showMessage('Echec de connexion', "Nom d'utilisateur ou mot de passe incorrect. Veuillez réessayer svp.");
}
} catch(e) {
Ti.API.error("Login : WS exists error : " + JSON.stringify(e));
$.actInd.hide();
$.actIndContainer.hide();
showMessage("Erreur de communication avec le serveur", "Erreur inconnue à survenue durant la communication avec le serveur. Veuillez réessayer svp. Si l'erreur persiste merci de contacter le support.");
}
},
onerror : function(e) {
//Ti.API.error("Login : Erreur de connexion :" + JSON.stringify(e));
$.actInd.hide();
$.actIndContainer.hide();
showMessage("Erreur de connexion", "Veuillez verifier votre connexion et réessayer svp.");
},
timeout : 10000 // in milliseconds
});
xhr.open("POST", Alloy.Globals.ws.url.login);
xhr.setRequestHeader('Authorization-Token', AuthorizationToken);
var device = Titanium.Platform.manufacturer + "," + Titanium.Platform.osname;
// + "," + Titanium.Platform.version + " " + Titanium.Platform.ostype + " " + Titanium.Platform.architecture + " " + Titanium.Platform.name;
var params = '{"UserName" : "' + user._userName + '","Password" : "' + user._userPassword + '","IP":"", "Device": "' + device + '", "Mobile" : true, "RememberMe" : true}';
Ti.API.error("PARAMS : " + params);
xhr.setRequestHeader('Content-Type', "application/json");
xhr.setRequestHeader("Content-length", params.length);
xhr.send(params);
The few solutions i found was to remove the setContentLength like in this answer for a similar question but i didn't find how to flush the buffer as it said there (there is no such as method in the titanium HTTPClient API) and i don't know if that's really the good solution for my problem anyway. So please anyone tell me what it could be.