NSURLConnection同步异步方式下获取status code

首先说说异步方式下的获取

#pragma mark NSURLConnection Delegate Methods
    - (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response {
         NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
         int responseStatusCode = [httpResponse statusCode];
    }

再来说说同步方式下的获取

NSHTTPURLResponse* urlResponse = nil;
NSError *error = [[NSError alloc] init];
responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];

int statusCode = [urlResponse statusCode];
int errorCode = error.code;




你可能感兴趣的:(NSURLConnection同步异步方式下获取status code)