AFNetworking 3.0 AFHTTPSessionManager using NSURLRequest

684 Views Asked by At

In AFNetworking 2.0 I am using AFHTTPRequestOperation. In this I can easily get NSURLRequest from following code.

AFHTTPRequestOperation *op;
self.fields = op.request.allHTTPHeaderFields[@"Fields"];

But now I am upgrading to AFNetworking 3.0 which is using AFHTTPSessionManager instead of AFHTTPRequestOperation. So, how can I achieve same result with AFHTTPSessionManager?

1

There are 1 best solutions below

0
Anjula Serasinghe On

I think what you are looking for is this ,

  NSURL *URL = [NSURL URLWithString:@"http://example.com/resources/123.json"];

  AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

  [manager GET:URL.absoluteString parameters:nil progress:nil 
  success:^(NSURLSessionTask *task, id responseObject) {
  NSLog(@"JSON: %@", responseObject);
  } 
  failure:^(NSURLSessionTask *operation, NSError *error) {
   NSLog(@"Error: %@", error);
}];

Also take a look at this migration guide which will help you greatly https://github.com/AFNetworking/AFNetworking/wiki/AFNetworking-3.0-Migration-Guide