Я использую AFHTTPRequestOperation, чтобы получить пару HTML-страниц для анализа. Проблема, с которой я сталкиваюсь, заключается в том, что если я использую неправильный номер порта, например, при подключении к серверу, блок ошибки «сбой» не срабатывает. Вместо этого срабатывает блок завершения, но строка ответа равна нулю. Я просто переключаюсь на AFNetworking с ASIHTTP, и с ASIHTTP это приведет к ошибке.
Конечно, это должно привести к ошибке? Как я могу поймать это?
NSString *urlString;
urlString = [NSString stringWithFormat:@"%@://%@:%@/",kHttp,_IP,_Port];
NSURL *url = [NSURL URLWithString:urlString];
// Set authorization
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
[httpClient setAuthorizationHeaderWithUsername:_User password:_Pass];
NSURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"Info.htm" parameters:nil];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
if ([self parseInfoLive:operation.responseString])
_count_parsed++;
if (_count_parsed == 2)
[[NSNotificationCenter defaultCenter] postNotificationName:@"downloadsComplete" object:nil];
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error during connection: %@",error.description);
[[NSNotificationCenter defaultCenter] postNotificationName:@"errorConnecting" object:nil];
}];
[operation start];