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;

转自: http://blog.csdn.net/favormm/article/details/7528089。

你可能感兴趣的:(ios)