AFN-OC版
AFNetworking代理封裝 用法
-(void)viewDidLoad {?
[super viewDidLoad];
[self accessToServerForGetGetLogin];?
}
pragma mark -- 網(wǎng)絡(luò)請(qǐng)求
-(void)accessToServerForGetGetLogin {
NSString *requestName = GetLoginKey;
NSString *url = @"http://apis.haoservice.com/lifeservice/cook/query?";
NSMutableDictionary *postInfo = [NSMutableDictionary dictionary];
postInfo[@"menu"] = @"土豆";
postInfo[@"pn"] = @1;
postInfo[@"rn"] = @"10";
postInfo[@"key"] = @"2ba215a3f83b4b898d0f6fdca4e16c7c";
[NetWorkRequest netWorkRequestByPostMode:url parameters:postInfo requestName:requestName delegate:self];
}
-(void)netWorkRequestSuccess:(id)data userInfo:(NSDictionary *)userInfo parameters:(NSDictionary *)getparameters {?
//服務(wù)器連接成功 NSString *requestUsername = [userInfo objectForKey:@"username"];
if ([requestUsername isEqualToString:GetLoginKey]) {
NSDictionary *dicR = (NSDictionary *)data;
NSLog(@"%@",dicR);
}
}?
-(void)netWorkRequestFailed:(NSError*)error userInfo:(NSDictionary *)userInfo parameters:(NSDictionary *)getparameters {
?//服務(wù)器連接失敗請(qǐng)重試 NSLog(@"%@",error);?
}
GitHub Demo下載地址:https://github.com/wzf1053132166/AFN-OC