在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庫,感受還不錯。git
AFNetworking庫的地址是github
https://github.com/AFNetworking/AFNetworking objective-c
在主頁能夠看到,AFNetworking庫的使用很簡單json
get請求post
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請求
spa
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.net