Saturday, May 11, 2013

NSHTTPURLResponse statusCode example ios


statusCode

Returns the receiver’s HTTP status code.
- (NSInteger)statusCode
Return Value
The receiver’s HTTP status code.
Example of [NSHTTPURLResponse statusCode]
- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
   NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
   int code = [httpResponse statusCode];
}
Example of [NSHTTPURLResponse statusCode]
- (void)connection:(NSURLConnection *)aConnection didReceiveResponse:(NSURLResponse*)response 
{
    if ([response isKindOfClass: [NSHTTPURLResponse class]])
        statusCode = [(NSHTTPURLResponse*) response statusCode];
}
Example of [NSHTTPURLResponse statusCode]
if (response) {
    NSHTTPURLResponse* newResp = (NSHTTPURLResponse*)response;
    NSLog(@"%d", newResp.statusCode);
}
else {
    NSLog(@"No response received");
}