I have this sweet method that authenticates a user, however I can't figure out how to get the status code of the request. I can clearly see it exists when I do NSLog(@"%@", response);
, but I can't find any way to pull it out of that. Is there a method or do I have to parse it myself somehow?
- (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);
}
Try this
NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response;
NSInteger statusCode = [HTTPResponse statusCode];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With