0

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);
}
BON
  • 433
  • 2
  • 9
  • 18
  • Do you have any example code for how I could do that? – BON Aug 12 '12 at 12:02
  • http://stackoverflow.com/questions/2053568/managing-http-cookies-on-iphone – La bla bla Aug 12 '12 at 12:07
  • I can see the cookie in the didReceiveResponse method but the response data is empty from the connectionDidFinishLoading method. When I look at the headers in chrome, the cookie has extra data and the login redirects me. But I dont see anything related to a redirect in the reponse. – BON Aug 13 '12 at 09:14

0 Answers0