在iOS下开发一直是用ASIHTTPRequest库,ASIHTTPRequest已经停止更新,看了这个文章 (原文)的库,感觉还不错。
库的地址是
在主页可以看到,库的使用很简单
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主页上看