我有这个甜蜜的方法来验证用户,但我无法弄清楚如何获取请求的状态代码。当我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);
}
答案 0 :(得分:10)
试试这个
NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response;
NSInteger statusCode = [HTTPResponse statusCode];