码迷,mamicode.com
首页 > 移动开发 > 详细

使用MKNetworkKit ios post请求

时间:2015-04-13 19:10:23      阅读:192      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!