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();
});
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.
-
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.
-
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 -
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
-
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.