I'm working on a project where I need to log into a site, retrieve a URL after logging in and parse the data. So far I have been able to parse some of the site data I need without logging in, but now I need to log in to retrieve the rest of the data.
I'm not sure how log in and store the session so I can retrieve another URL. The response I get from the the following code does not contain any data. The responseData and responseString are empty.
- (void) login {
NSMutableURLRequest *loginRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.theSite.com/booker/admin.php"]];
NSString *postString = @"go=1&NewUserName=testUserName&NewUserPassword=testPassword&returl=http://www.theSite.com/booker/day.php?day=12&month=08&year=2012&area=0&room=3&TargetURL=http://www.theSite.com/booker/day.php?day=12&month=08&year=2012&area=0&room=3&day.php?day=12&month=08&year=2012&area=0&room=3&Action=SetName";
[loginRequest setHTTPMethod:@"POST"];
[loginRequest setValue:[NSString stringWithFormat:@"%d", [postString length]]
forHTTPHeaderField:@"Content-length"];
[loginRequest setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
[[NSURLConnection alloc] initWithRequest:loginRequest delegate:self];
}
- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
responseData = [NSMutableData new];
NSString* responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"the html was %@", responseString);
}