Titanium.Network.createHTTPClient not sending cookies
Hi,
My request goes through but does not send any cookies.
Am I missing something?
var MyURL = "http://someurl.com/content.php"
var MyRequest = Titanium.Network.createHTTPClient();
MyRequest.open('GET', MyURL);
var requestCookies = "userid=1; password=098f6bcd4621d373cade4e832627b4f6";
alert(requestCookies);
LoginRequest.setRequestHeader("Cookie", requestCookies);
MyRequest.setRequestHeader("Connection", "close");
MyRequest.send();
10 Answers
-
For me it works if I just split the cookie into multiple lines of xhr.setRequestHeader.
xhr = Ti.Network.createHTTPClient(); xhr.open(method, url, false); xhr.setRequestHeader('Cookie',"session=CIGNUMTDNBRJVEYXVYTWGIVXCNILHGSQQHECIPJU;"); xhr.setRequestHeader('Cookie',"city=747;"); xhr.send();
-
It´s long Time ago, but i use Cookies too and its working…
You set the Cookie to "LoginRequest" but you send "MyRequest"…
Change "LoginRequest" to "MyRequest" and it will work!
var MyURL = "http://someurl.com/content.php" var MyRequest = Titanium.Network.createHTTPClient(); MyRequest.open('GET', MyURL); var requestCookies = "userid=1; password=098f6bcd4621d373cade4e832627b4f6"; alert(requestCookies); MyRequest.setRequestHeader("Cookie", requestCookies); // THIS ONE MyRequest.setRequestHeader("Connection", "close"); MyRequest.send();
-
Which platfoms?
-
I'm trying it on iphone simulator.
-
To be honest, I would look in alternative methods than cookies, which are simply unreliable, even in a non-mobile environment
utilize Titanium's App.Properties and store the values there and send them with the request to the remote server
that's just my 2 cents trying to help
-
Ok now i see i have a problem too…he isn´t deliver the cookie…
I have to Send in one request a cookie…there is no other way for me!
//EDIT : so i take a look at
http://github.com/appcelerator/titanium_mobile/commit/4638029de839e581b128729a8f592e486bbdd7b7#diff-2i patched my TiNetworkHTTPClientProxy.m …
When i look at it, i have to set for each Value a setRequestHeader right?
He don´t sending Cookie Data…
//EDIT 2 : the xhr exmpale works … whats wrong hu?
-
Ok i tested it again with my Serverurl and a little Script reading out the COOKIEs….
When i´m using the example xhr_cookie.js everything works fine…he reads out the cookie i´m sending!
but if i copy the code into my project no cookie is send!!!
I try just the Code for sending cookie without making everything else in my project.. it doesn´t work!
why? please help!
-
hey,
i test it in a blank new project and it works…var tokenUrl = 'http://www.URL.com/test.php'; var tokenRequest = Ti.Network.createHTTPClient(); tokenRequest.open('GET', tokenUrl); tokenRequest.onload = function() { }; var requestCookies = "SID=Test"; tokenRequest.setRequestHeader("Cookie", requestCookies); tokenRequest.send();
In a fresh project it works…in my project i want to use it doesn't work..
does i have to clear any cache? -
take a look, uses cookies from response. works in 1.4
http://www.tine20.org/forum/viewtopic.php?f=12&t=4608&p=18980#p18980 -
I seem to get problems as soon as I have more than one cookie (only tested on iPhone).
… …
var cookieString = "session=CIGNUMTDNBRJVEYXVYTWGIVXCNILHGSQQHECIPJU; city=747;";
xhr = Ti.Network.createHTTPClient();
xhr.open(method, url, false);
xhr.setRequestHeader('Cookie', cookieString);
xhr.send();… …
If I remove the second variable from the cookieString it works… As soon as I add it back, it fails.
This seems to be the correct format for cookies in HTTP headers.
Anyone else noticing this with multiple cookie variables?