Does the new added download function handle cookies?

48 views
Skip to first unread message

Evan Tan

unread,
Dec 12, 2011, 6:15:33 AM12/12/11
to phonegap
hi there,

Finally, the long-awaited download function was added to filetransfer
recently on github.
But when check android code, i cannot find any cookie related
code.Does it handle cookies?In widespread situations we need some
session cookie to authenticate before downloading.

aflx

unread,
Dec 12, 2011, 8:41:59 AM12/12/11
to phonegap
No, not in the current version.
I will try to add it later.

Evan Tan

unread,
Dec 12, 2011, 12:51:08 PM12/12/11
to phonegap
Thanks for your nice work! Hope to see it in 1.3.0
For me, phonegap is 99% perfect except this function.

For now i can add few lines myself to add cookie handler in my android
re-building,but i know nothing about ios native code.
Can anyone here give me some hints?
Thx~

aflx

unread,
Dec 12, 2011, 3:41:36 PM12/12/11
to phonegap
I think on Android you just need to add the following lines in the
download method:

// Set the cookies on the response
String cookie = CookieManager.getInstance().getCookie(source);
if (cookie != null) {
connection.setRequestProperty("Cookie", cookie);
}

It is similar to the upload function.

On iOS you could try to allow all cookies:

NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage
sharedHTTPCookieStorage];
[cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
//NSArray* cookies = [cookieStorage cookiesForURL:[NSURL
URLWithString:sourceUrl]];

At the moment I don't have a test case for this.

Evan Tan

unread,
Dec 13, 2011, 3:32:18 PM12/13/11
to phonegap
Thanks for your tips, and i made some test both on simulator(iphone)
and real device(HTC):

On andriod, your provided codes work very well;

On iOS, it seems no need to use "setCookieAcceptPolicy", because in
source file PhoneGapDelegate.m, sharedHTTPCookieStorage already set to
"NSHTTPCookieAcceptPolicyAlways".Change nothing and work fine.

aflx

unread,
Dec 14, 2011, 12:56:37 AM12/14/11
to phonegap
Ah! Thanks @Evan.
Reply all
Reply to author
Forward
0 new messages