Titanium Community Questions & Answer Archive

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

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();
— asked March 12th 2010 by Pritesh Shah
  • cookies
  • createhttpclient
0 Comments

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();
    
    — answered September 9th 2012 by Louis van de Wiele
    permalink
    0 Comments
  • 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();
    
    — answered June 10th 2010 by Christian Brauwers
    permalink
    0 Comments
  • Which platfoms?

    — answered March 12th 2010 by Don Thorp
    permalink
    0 Comments
  • I'm trying it on iphone simulator.

    — answered March 15th 2010 by Pritesh Shah
    permalink
    0 Comments
  • 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

    — answered June 10th 2010 by Stephen Gilboy
    permalink
    0 Comments
  • 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-2

    i 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?

    — answered June 10th 2010 by Christian Brauwers
    permalink
    0 Comments
  • 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!

    — answered June 10th 2010 by Christian Brauwers
    permalink
    1 Comment
    • Can you attach the code you're using in an app.js file folks can drop into a project and look at?

      — commented June 10th 2010 by Kevin Whinnery
  • 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?

    — answered June 10th 2010 by Christian Brauwers
    permalink
    0 Comments
  • 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

    — answered November 16th 2010 by Kay Strobach
    permalink
    0 Comments
  • 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?

    — answered May 6th 2011 by Deric Davis
    permalink
    1 Comment
    • I too have same issues. Any update on this?

      — commented May 23rd 2012 by Saamy
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.