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];
时间: 2024-10-07 16:13:43