Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20229] Android: Titanium.Network."Cookie" API is not Working.

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2016-02-29T03:06:20.000+0000
Affected Version/sn/a
Fix Version/sRelease 5.2.1
ComponentsAndroid
LabelsAndroid, cookies, webView
ReporterMotiur Rahman
AssigneeAshraf Abu
Created2016-01-13T09:10:42.000+0000
Updated2016-03-03T00:08:01.000+0000

Description

We tried to setup cookie on a web view using this method "createCookie", "addHTTPCookie" and "addSystemCookie". But it does not work it only reads the default cookies but not set the cookie. Please take a look my sample code. *Steps to reproduce* 1. Just run this sample code then check the consol log.
var win = Ti.UI.createWindow({
	layout : 'vertical'
});
var url = 'http://www.appcelerator.com/'; //Or any html file
var reload = Ti.UI.createButton({
	title : 'reload',
	height : 50,
	width : 100,
	top : 5,
});

reload.addEventListener('click', function() {
	web.url = url;
});

win.add(reload);

var web = Ti.UI.createWebView({
	url : url,
	width : Ti.UI.FILL,
	top : 100,
	height : Ti.UI.FILL,

});

win.add(web);
var i = 1;

web.addEventListener('load', function(e) {

	var d = new Date();
	d.setTime(d.getTime() + (2 * 24 * 60 * 60 * 1000));
	
	// You can try this("addHTTPCookie",  "addSystemCookie") insted of "createCookie"

	var cookie = Ti.Network.createCookie({
		name : 'helloWorld',
		domain : url,
		value : "testCoockie",
		expiryDate : d,

	});

	Ti.API.info("createCookie -> " + JSON.stringify(cookie));

	var cookies = web.evalJS("document.cookie").split(";");
	Ti.API.info("# of cookies -> " + cookies.length);
	for ( i = 0; i <= cookies.length - 1; i++) {
		Ti.API.info("cookie -> " + cookies[i]);
	}

});

win.open();


Thanks.

Comments

  1. Ashraf Abu 2016-02-11

    PR: https://github.com/appcelerator/titanium_mobile/pull/7706
  2. Ashraf Abu 2016-02-29

    PR merged into master
  3. Ashraf Abu 2016-02-29

    Backport 5_2_X: https://github.com/appcelerator/titanium_mobile/pull/7784 [~hpham] for review.
  4. Lokesh Choudhary 2016-03-03

    Verified the fix. "createCookie", "addHTTPCookie" and "addSystemCookie" works as expected. Closing. Environment: Appc Studio : 4.5.0.201602170831 Ti SDK : 5.2.1.v20160228190750 Ti CLI : 5.0.6 Alloy : 1.7.33 MAC El Capitan : 10.11.13 Appc NPM : 4.2.3 Appc CLI : 5.2.0 Node: 4.2.2 Nexus 6P - Android 6.0.1

JSON Source