How to do GET request via AFNetworking?

user2565968 picture user2565968 · Jan 6, 2016 · Viewed 22.6k times · Source

I added directories AFNetworking and UIKit+AFNetworking to project manager. I use latest library 3.0.4

After I imported file AFNetworking.h in my class file .m. I found a lot examples how to make request to url, but information is old.

How to make GET request to URL and get data from server? Now function AFHTTPRequestOperation was removed.

This is first time working with libraries in xcode, I am beginner.

Answer

Chanchal Raj picture Chanchal Raj · Jun 7, 2016

For AFNetworking 3.x:

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager GET:@"http://example.com/resources.json" parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
} failure:^(NSURLSessionTask *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];