Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-263] Android: Not forwarding cookies in HTTPClient

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionDuplicate
Resolution Date2012-05-08T10:36:13.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsandroid, defect
ReporterDon Thorp
AssigneeNeeraj Gupta
Created2011-04-15T02:26:21.000+0000
Updated2017-03-21T22:39:59.000+0000

Description

From http://support.appcelerator.net/discussions/announcements/191-cookies-in-httpclient-request"> cookies in httpclient request

I am developing an app that uses AJAX style requests back to a host server. This works fine on the iPhone but not in Android.

I have to first authenticate which sets a cookie for subsequent calls. It seems like on android this cookie is not being returned on subsequent calls.

Comments

  1. Dawson Toth 2012-05-08

    I believe this has been addressed by [TIMOB-2849]. The following code tests cookie interaction. Cookies do persist across sessions, hence my assertion that this is resolved.
       var win = Titanium.UI.createWindow({ backgroundColor:'#fff' });
       var testServer = 'http://appc.me/Test/Cookies/';
       
       /**
        * Create a text area to show responses from the server.
        */
       var response = Titanium.UI.createTextArea({
           left: 0, right: 0, top: 0, bottom: 30,
           value: 'Click a button below, and the response from the server will show up here!'
       });
       win.add(response);
       
       /**
        * Create a button that will hit a page on a test server that echoes any cookies we send it, or sends us two cookies.
        */
       var getOrSetCookies = Titanium.UI.createButton({ title : 'Get or Set Cookies', left: 0, bottom: 0, width: 150, height: 30 });
       getOrSetCookies.addEventListener('click', function(e) {
           var xhr = Ti.Network.createHTTPClient();
           xhr.onload = function(e) {
               response.value = this.responseText
                       + '\n\nthis.getResponseHeader(\'Set-Cookie\'): '
                       + this.getResponseHeader('Set-Cookie');
           };
           xhr.open('GET', testServer + '?count=2&clear=false');
           xhr.send();
       });
       win.add(getOrSetCookies);
       
       /**
        * Create a button that will clear the cookies on the server (set them to expire). It will tell us how many were cleared.
        */
       var clearCookies = Titanium.UI.createButton({ title : 'Clear Cookies', right: 0, bottom: 0, width: 150, height: 30 });
       clearCookies.addEventListener('click', function(e) {
           var xhr = Ti.Network.createHTTPClient();
           xhr.onload = function(e) {
               response.value = this.responseText
                       + '\n\nthis.getResponseHeader(\'Set-Cookie\'): '
                       + this.getResponseHeader('Set-Cookie');
           };
           xhr.open('GET', testServer + '?count=2&clear=true');
           xhr.send();
       });
       win.add(clearCookies);
       
       win.open();
       
  2. Neeraj Gupta 2012-05-08

    Duplicate of TIMOB-2849.
  3. Lee Morris 2017-03-21

    Closing ticket as duplicate.

JSON Source