首页 > 移动平台 > 详细

使用MKNetworkKit ios post请求

时间:2015-04-13 19:08:30      阅读:203      评论:0      收藏:0      [点我收藏+]
AppDelegate *appDelegate = [[UIApplicationsharedApplication] delegate];
    
    MKNetworkEngine *engine = [[MKNetworkEnginealloc] initWithHostName:appDelegate.baseUrlcustomHeaderFields:nil];
    NSMutableDictionary *dic = [[NSMutableDictionaryalloc] init];
    [dic setValue:@"kendeji"forKey:@"user.userCode"];
    [dic setValue:@"888888"forKey:@"user.password"];
    
    MKNetworkOperation *op = [engine operationWithPath:@"/dianCaiLogin.action"params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        NSLog(@"[operation responseData]-->>%@", [operation responseString]);
        NSError *error;
        NSData * data = [[operation responseString] dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *dic = [NSJSONSerializationJSONObjectWithData:data options:NSJSONReadingMutableContainerserror:&error];
        
        if(!dic ||error){
            NSLog(@"解码失败!");
            
        }else{
            BOOL isSuccess = [dic objectForKey:@"success"];
            if(isSuccess){
                UIAlertView * alert = [[UIAlertViewalloc] initWithTitle:@""message:@"登录成功!"delegate:selfcancelButtonTitle:@"好"otherButtonTitles:nil, nil];
                [alert show];
            }
            NSLog(@"%@", [dic objectForKey:@"success"]);
        }
        
    }errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
    }];
    [engine enqueueOperation:op];



使用MKNetworkKit ios post请求

原文:http://my.oschina.net/u/1011854/blog/400652

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!