Manted
Manted

Reputation: 109

How to get cookie using objective-c

I'm converting a java applet program to ipad version.

In the original java applet code, there are some code to get cookie from javascript:

    JSObject browser = (JSObject) JSObject.getWindow(this);
    JSObject document =  (JSObject) browser.getMember("document");
    String cookie = (String)document.getMember("cookie"); 

So, how can I get this cookie using objective-c? Are there any similar classes or methods that can do the same thing? Thanks. :)

========UPDATE========

NSString *cookie = [webView stringByEvaluatingJavaScriptFromString:@"document.cookie"];

using this method can read values from javascript code

Upvotes: 0

Views: 1459

Answers (2)

Manted
Manted

Reputation: 109

I found a way to get cookies.

NSString *cookie = [webView stringByEvaluatingJavaScriptFromString:@"document.cookie"];

using this method can read a value directly from javascript

Upvotes: 0

Gabriele Petronella
Gabriele Petronella

Reputation: 108169

Check out the NSHTTPCookieStorage documentation.

Upvotes: 1

Related Questions