从NSURLResponse中提取数据

从NSURLResponse中提取数据

我有一个可以验证用户身份的方法,但是我不知道如何获取请求的状态码。当我执行NSLog(@"%@", response);时,我可以清楚地看到它的存在,但是我找不到任何方法可以将其退出。有没有一种方法或者我自己必须以某种方式解析它?

- (BOOL)authenticateUserWithEmail:(NSString *)email password:(NSString *)password
{
    NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:
                                         @"%@/users/sign_in.json?user[email]=%@&user[password]=%@&user[remember_me]=true",
                                         LURL,
                                         email,
                                         password]];
    NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:url];
    [urlRequest setHTTPMethod:@"POST"];
    NSURLResponse *response;
    NSError *error;
    NSData *responseData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
    NSLog(@"Response: %@", [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding] );
    NSLog(@"Response Meta: %@", response);
    return (error == NULL);
}

最佳答案

试试这个

NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response;
NSInteger statusCode = [HTTPResponse statusCode];

关于ios - 从NSURLResponse中提取数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18950763/

10-09 13:01