如何使用目标c登录站点

时间:2012-08-12 11:46:09

标签: iphone objective-c forms http ios5

我正在开展一个项目,我需要登录一个站点,登录后检索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);
}

0 个答案:

没有答案