Benim previous question Benim bir bağlantı gönderme veya resim yükleme gibi web hizmetleri yapmak için her zaman giriş yapmak zorunda sorun hakkındaydı. Philipe, her istek için giriş işlemi yerine çerez kullanmam gerektiğini söyledi. ,Çerezler nasıl alınır ve POST (iOS) gibi diğer istekler için kullanılabilir?
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookies];
İşte yazabilmek için benim yöntemdir: Ben de bu çerezleri kullanmak için bu kodu bulundu
- (void)getCookies {
NSHTTPURLResponse * response;
NSError * error;
NSMutableURLRequest *request;
request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://MyWebsite.com/login.php"]
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:120];
NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]);
NSArray * all = [NSHTTPCookie cookiesWithResponseHeaderFields:[response allHeaderFields] forURL:[NSURL URLWithString:@"http://MyWebsite.com/login.php"]];
NSLog(@"%d", all.count);
for (NSHTTPCookie *cookie in all) {
NSLog(@"Name: %@ : Value: %@", cookie.name, cookie.value);
NSLog(@"Comment: %@ : CommentURL: %@", cookie.comment, cookie.commentURL);
NSLog(@"Domain: %@ : ExpiresDate: %@", cookie.domain, cookie.expiresDate);
NSLog(@"isHTTPOnly: %c : isSecure: %c", cookie.isHTTPOnly, cookie.isSecure);
NSLog(@"isSessionOnly: %c : path: %@", cookie.isSessionOnly, cookie.path);
NSLog(@"portList: %@ : properties: %@", cookie.portList, cookie.properties);
NSLog(@"version: %u", cookie.version);
}
}
ama nasıl kullanılacağını emin değilim: Ben almak çerezler için bu yöntemi bulundu Ben RestKit API kullanıyorum:
- (IBAction)addLinkPressed:(UIButton *)sender {
[RKClient clientWithBaseURLString:@"http://MyWebsite.com"];
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
self.linkField.text, @"url",
self.linkTitleField.text, @"title",
self.linkSummaryField.text, @"summary",
nil];
RKRequest *request = [[RKClient sharedClient] post:@"/send_link.php" params:params delegate:self];
[request setUserData:@"sendLink"];
}
Soru: giriş bilgileri için kullanmak saklamalısınız ve nerede benim kodunda o koymalıyız çerez mülkiyet?
hiçbir çözüm henüz (Bu kullanıcının şifresini değiştirmek istediği zaman içindir)? –
@FadyKamal Metodolojimi gönderiyorum, umarım size yardımcı olur. – Hamid