使用MKNetworkKit ios post请求

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];



郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。