I am using AFNetworking 2.0 in an iOS project and I am trying to create a GET request with some parameters and intercept redirects.
I see a method -[AFHTTPRequestOperation setRedirectResponseBlock]that I use to capture redirects and do something with them. But I do not see how to set the request parameters for this operation. Here's what it looks like:
AFHTTPRequestOperation *ballotOperation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest];
[ballotOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"in completion");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"in error");
}];
[ballotOperation setRedirectResponseBlock:^NSURLRequest *(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse) {
if (redirectResponse == nil) {
return request;
} else {
NSLog(@"in redirect, blocking");
[ballotOperation cancel];
return nil;
}
}];
[[AFHTTPRequestOperationManager manager].operationQueue addOperation:ballotOperation];
I see that it AFHTTRequestOperationManagerhas a method GET:parameters:success:failure:in which you can set the parameters. But this immediately launches the request, does not give me the opportunity to install a redirect unit on it.
I see some sample code from AFNetworking 1.x using AFHTTPClient, but I don't want to come back!
How can I do what I'm trying to do?