【发布时间】:2015-04-01 22:19:18
【问题描述】:
我正在尝试使用 AFHTTPRequestOperationManager 发出 HTTP 请求。我需要使用 AFHTTPRequestOperationManager 因为我希望能够在必要时取消所有操作。由于某种原因,我无法使其正常工作。不调用完成块。我错过了什么吗?
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);
}];
【问题讨论】:
标签: ios objective-c http afnetworking nsurlrequest