I\'m new to the forum and also quite new to iOS Dev. I\'m having trouble with a UIWebView, where I keep losing login permission to a HTML form which sets a phpsession cookie
I use in my app many requests and every time when I send a request I get the cookies for the url from NSHTTPCookieStorage
. I do not use NSUserDefaults
or something else to store the cookies.
When I send a new request I set the needed cookies my self
NSURL *myURL = ....
NSMutableRequest *mutableRequest = ....
NSArray *cookiesToSet = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:myURL];
for (NSHTTPCookie *cookie in cookiesToSet) {
[cookieStringToSet appendFormat:@"%@=%@;", cookie.name, cookie.value];
}
if (cookieStringToSet.length) {
[mutableRequest setValue:cookieStringToSet forHTTPHeaderField:@"Cookie"];
}
And it works