I use following code to create a cookie, but faild.(iOS SDK 5)
// add cookie
NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys:
req.URL, NSHTTPCookieOriginURL,
@"MLSTORAGE", NSHTTPCookieName,
@"1234567890", NSHTTPCookieValue,
nil];
NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:properties];
NSLog(@"\nurl: %@\ncookie: %@", req.URL, cookie);
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
//
the log is:
2012-07-26 18:30:49.914 Motilink[15289:707] -[FMWebDAVRequest sendRequest:][Line 154]
url: http://210.116.114.195:8080/MLServer/storage/
cookie: (null)
any one know how to create a cookie?
It seems that there is a problem when using NSHTTPCookieOriginURL
with your request's URL.
Try using this code, it worked for me :
// add cookie
NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys:
req.URL.host, NSHTTPCookieDomain,
req.URL.path, NSHTTPCookiePath,
@"MLSTORAGE", NSHTTPCookieName,
@"1234567890", NSHTTPCookieValue,
nil];
NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:properties];
NSLog(@"\nurl: %@\ncookie: %@", req.URL, cookie);
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
//
However, I don't know why NSHTTPCookieOriginURL
doesn't work here.
Hope this helps,
To successfully create a cookie, you must provide values for (at least) the NSHTTPCookiePath, NSHTTPCookieName, and NSHTTPCookieValue keys, and either the NSHTTPCookieOriginURL key or the NSHTTPCookieDomain key.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With