Login auth using POST
I haven't been able to figure out how to POST data using the createHTTPClient() method. Right now I have:
var loginReq = Titanium.Network.createHTTPClient();
loginReq.onreadystatechange = function()
{
if (this.readyState == 4)
{
alert(this.responseText);
}
};
loginBtn.addEventListener('click',function(e)
{
if (username.value != '' && password.value != '')
{
loginReq.open("POST","http://localhost:8888/post_auth.php?username=" + username.value + "&password=" + Ti.Utils.md5HexDigest(password.value));
loginReq.send();
}
else
{
alert("Username/Password are required");
}
});
The above works fine, however, my PHP then has to use the GET method to get the variables. I want to know how I can use the POST method in my PHP and just call http://localhost:8888/post_auth.php rather than adding all my params at the end.
2 Answers
-
Accepted Answer
Try this
loginBtn.addEventListener('click',function(e) { loginReq.setRequestHeader("content-type", "multipart/form-data"); if (username.value != '' && password.value != '') { loginReq.open("POST","http://localhost:8888/post_auth.php"); var parms = { username: username.value, password: Ti.Utils.md5HexDigest(password.value) }; loginReq.send(parms); } else { alert("Username/Password are required"); } });
-
hello i'm trying with the same sentaxe but it's not work!!!the database can't be opened.help me plz