[webkit-dev] How to set a cookie for a url ?
hewanxiang at gmail.com
Mon Aug 18 02:53:33 PDT 2008
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)
67 // <rdar://problem/5632883> On 10.5, NSHTTPCookieStorage would
happily store an empty cookie, which would be sent as "Cookie: =".
68 if (cookieStr.isEmpty())
71 NSURL *cookieURL = url;
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 + "=";
77 NSArray *cookies = [NSHTTPCookie
78 [[NSHTTPCookieStorage sharedHTTPCookieStorage]
setCookies:cookies forURL:cookieURL mainDocumentURL:policyBaseURL];
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