[TIMOB-20229] Android: Titanium.Network."Cookie" API is not Working.
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2016-02-29T03:06:20.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 5.2.1 |
Components | Android |
Labels | Android, cookies, webView |
Reporter | Motiur Rahman |
Assignee | Ashraf Abu |
Created | 2016-01-13T09:10:42.000+0000 |
Updated | 2016-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.
PR: https://github.com/appcelerator/titanium_mobile/pull/7706
PR merged into master
Backport 5_2_X: https://github.com/appcelerator/titanium_mobile/pull/7784 [~hpham] for review.
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