0

我正在做一个项目,我需要登录一个站点,登录后检索一个 URL 并解析数据。到目前为止,我已经能够在不登录的情况下解析我需要的一些站点数据,但现在我需要登录才能检索其余数据。

我不确定如何登录和存储会话,以便检索另一个 URL。我从以下代码得到的响应不包含任何数据。responseData 和 responseString 为空。

- (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);
}
4

0 回答 0