[webkit-dev] How to set a cookie for a url ?
Andy
hewanxiang at gmail.com
Mon Aug 18 02:53:33 PDT 2008
Hi, all,
I want to set a cookie for a url, the cookie comes from a cookie
string, I don't know what the format of the cookie string is supposed
to be, should be like this ?? "NAME=VALUE; expires=DATE; path=PATH;
domain=DOMAIN_NAME " , is there any standard to comply with ?
I also have another question. In mac os x, there is a class named
"NSHTTPCookie", I'm a little confused with how to use it. I googled a
example like this.
void setCookies(Document* /*document*/, const KURL& url, const KURL&
policyBaseURL, const String& cookieStr)
64 {
65 BEGIN_BLOCK_OBJC_EXCEPTIONS;
66
67 // <rdar://problem/5632883> On 10.5, NSHTTPCookieStorage would
happily store an empty cookie, which would be sent as "Cookie: =".
68 if (cookieStr.isEmpty())
69 return;
70
71 NSURL *cookieURL = url;
72
73 // <http://bugs.webkit.org/show_bug.cgi?id=6531>, <rdar://4409034>
74 // cookiesWithResponseHeaderFields doesn't parse cookies without a value
75 String cookieString = cookieStr.contains('=') ? cookieStr :
cookieStr + "=";
76
77 NSArray *cookies = [NSHTTPCookie
cookiesWithResponseHeaderFields:[NSDictionary
dictionaryWithObject:cookieString forKey:@"Set-Cookie"]
forURL:cookieURL];
78 [[NSHTTPCookieStorage sharedHTTPCookieStorage]
setCookies:cookies forURL:cookieURL mainDocumentURL:policyBaseURL];
79
80 END_BLOCK_OBJC_EXCEPTIONS;
81 }
In the example, I guess the "cookieStr" is my "cookie string", but
when I pass a string "safarname=safarivalue; expires=Thu, 2 Aug 2009
20:47:11 UTC; path=/; domain=example.com " to it, the method
"cookiesWithResponseHeaderFields:" can't parse it into a cookie
successfully, so can not return a cookie array, also, the method
"setCookies:" failed, is there any problem with my cookie string ?
Bless my poor English, I wish I make my mind clear.
Thanks in advance && thanks for your time.
More information about the webkit-dev
mailing list