我正在尝试使用AFHTTPRequestOperationManager发出HTTP请求。我需要使用AFHTTPRequestOperationManager,因为我希望能够在必要时取消所有操作。出于某种原因,我无法正常工作。完成块不被调用。我错过了什么吗?如何使用AFNetorking和NSURLRequest进行HTTP请求?
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://twitter.com/%@", username]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setValue:@"MyUserAgent (iPhone; iOS 7.0.2; gzip)" forHTTPHeaderField:@"User-Agent"];
[request setHTTPMethod:@"GET"];
[self.manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *html = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
if ([html containsString:@"var h = decodeURI(l.hash.substr(1)).toLowerCase();"]) {
completion(YES, nil);
} else {
completion(NO, nil);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
completion(NO, error);
}];
我是想,因为我使用的是共享经理的一切,这样如果需要的话,我可以一次取消所有异步操作做这个不可思议的方式这实际上是我的应用程序非常需要的功能。但是,我只是决定让第二位经理拥有我想要的单独头域。谢谢。 – shakked 2015-04-01 22:52:50