Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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.

— asked October 8th 2010 by Ronnie Swietek
  • authentication
  • get
  • login
  • post
0 Comments

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");
        }
    });
    
    — answered October 8th 2010 by John McKnight
    permalink
    0 Comments
  • hello i'm trying with the same sentaxe but it's not work!!!the database can't be opened.help me plz

    — answered July 29th 2011 by Rajaa Samaha
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.