在iOS下开发一直是用ASIHTTPRequest库,ASIHTTPRequest已经停止更新,看了这个文章http://www.oschina.net/news/61416/github-top-100-objective-c-projects (原文https://github.com/Aufree/trip-to-iOS/blob/master/Top-100.md)的AFNetworking库,感觉还不错。
AFNetworking库的地址是
https://github.com/AFNetworking/AFNetworking
在主页可以看到,AFNetworking库的使用很简单
get请求
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }];
post请求
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; NSDictionary *parameters = @{@"foo": @"bar"}; [manager POST:@"http://example.com/resources.json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }];
还有很多使用方法,可以直接到GitHub主页上看https://github.com/AFNetworking/AFNetworking
时间: 2024-10-27 12:41:10