Titanium Community Questions & Answer Archive

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

Httpclient Multiple Requests

I've been trying to keep the cookies across multiple requests, Does Appcelerator handle that, or do i have to store the cookies and set them manually for each request?

As in can a single httpclient instance be used to make multiple http requests, Hopefully allowing the cookies to be stored between requests.

I Connect to the login script

var loginbutton = Titanium.UI.createButton();
loginbutton.addEventListener('click',function(e){
var data = {};
data.Login = username.value;
data.Password = password.value;

c.open('POST', 'http://testserver/json/login');
c.send(data);
});

then try to connect to the web service

var testbutton = Titanium.UI.createButton({top:250});
testbutton.addEventListener('click',function(e){
  c.close();
c.open('GET', 'http://testserver/Cricket.php');
c.send();
});
— asked May 29th 2010 by Ryan Tregea
  • android
  • cookie
  • httpclient
0 Comments

5 Answers

  • Accepted Answer

    We really should probably treat this as a bug. In my opinion, we should keep all session cookies for same domains across all XHR requests. I'll open issue for this.

    — answered May 29th 2010 by Jeff Haynie
    permalink
    1 Comment
    • I opened a issue.

      — commented May 29th 2010 by Jeff Haynie
  • It doesn't look like headers are persisted between requests - so you'll need to grab and store the response headers yourself and then add them to subsequent requests.

    You can grab specific headers - such as cookies - and save them with Titanium.App.Properties.

    — answered May 29th 2010 by David Ashwood
    permalink
    0 Comments
  • Thats what i thought, I found some code for that in another question, which led me to wonder if that was the case.
    I'll proceed with that line of coding tomorrow when i wake up.

    I'd like to say, I am loving Appcelerator, I wrote 4 apps in a day and published to market.
    Will be good when there's more native support for each platform

    — answered May 29th 2010 by Ryan Tregea
    permalink
    1 Comment
    • Can you tell me where you found the code, and if it worked? I can't find it on these forums :(
      Thanks,
      JH

      — commented June 4th 2010 by John Holman
  • Also that wasn't iPhone as stated in the issue, it was android, I'd hope that android would see that fix in 1.4 as well :D

    — answered May 29th 2010 by Ryan Tregea
    permalink
    0 Comments
  • Just what I was looking to have answered. If someone has a bug number I'd like to keep track of this issue. I too would like to see all session information saved in the HTTPClient so I may reuse it for multiple request.

    — answered June 1st 2010 by Josh Orchard
    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.