读书人

Is there a better way to handle HTT

发布时间: 2012-09-20 09:36:50 作者: rapoo

Is there a better way to handle HTTP error statuses?

if ([response respondsToSelector:@selector(statusCode)]){    int statusCode = [((NSHTTPURLResponse *)response) statusCode];    if (statusCode >= 400)    {        [connection cancel];  // stop connecting; no more delegate messages        NSDictionary *errorInfo          = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:            NSLocalizedString(@"Server returned status code %d",@""),            statusCode]                                        forKey:NSLocalizedDescriptionKey];        NSError *statusError          = [NSError errorWithDomain:NSHTTPPropertyStatusCodeKey                                code:statusCode                            userInfo:errorInfo];        [self connection:connection didFailWithError:statusError];    }}?

读书人网 >Ruby Rails

热点推荐