常用框架比如:AFNetworking,ASIHttpRequest,SDWebImage,MKNetWorkKit等。
iOS5已出来这么久了,而ASIHttpRequest的作者已经申明不更新了,在iOS5环境下,其实还是有些问题的。
现在MKNetWorkKi吸取了ASIHttpRequest与AFNetWorking的优点,并加入了自己特有的功能。
下载:
github下载了该项目后,如果想运行其demo,一定要打开MKNetworkKit.xcworkspace该文件,若单独打开,则编译时会提示缺少libMKNetworkKit-iOS.a文件!!!
安装方法
Installation
The preferred way of installation is via CocoaPods. Just add
pod 'MKNetworkKit'
and run pod install
. It will install the most recent version of MKNetworkKit.
If you would like to use the latest code of MKNetworkKit use:
pod 'MKNetworkKit', :head
安装成功后
实现get请求
1 MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:@"www.weather.com.cn" customHeaderFields:nil]; MKNetworkOperation *op = [engine operationWithPath:@"/data/sk/101010100.html" params:nil httpMethod:@"GET" ssl:NO]; [op addCompletionHandler:^(MKNetworkOperation *operation) { 2 NSLog(@"[operation responseData]-->>%@", [operation responseString]); 3 }errorHandler:^(MKNetworkOperation *errorOp, NSError* err) { 4 NSLog(@"MKNetwork request error : %@", [err localizedDescription]); 5 }]; 6 [engine enqueueOperation:op];