Mithilfe der NSURLConnection-Klasse können Sie eine HTTP-Anforderung zum Anmelden der Website und zum Abrufen des Cookies ausführen. Um eine Anfrage auszuführen, erstellen Sie einfach eine Instanz von NSURLConnection und weisen Sie ihr ein Delegate-Objekt zu.
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com/"]];
NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:self];
Implementieren Sie eine Delegate-Methode.
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response;
NSDictionary *fields = [HTTPResponse allHeaderFields];
NSString *cookie = [fields valueForKey:@"Set-Cookie"]; // It is your cookie
}
Behalten oder kopieren Sie die Cookie-Zeichenfolge. Wenn Sie eine weitere Anfrage ausführen möchten, fügen Sie sie Ihrem HTTP-Header Ihrer NSURLRequest-Instanz hinzu.
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com/"]];
[request addValue:cookie forHTTPHeaderField:@"Cookie"];
A * Python * -App? 'WWW :: Mechanize' ist eine Perl-Bibliothek. –
Es gibt auch einen Python-Port. http://www.search.sourceforge.net/mechanize/ – dan