iOS 网络请求--- AFNetworing的使用


一、GET请求方式:

    //1.管理器
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    //2.设置参数
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"param1"] = @"1";
    params[@"param2"] = @"2";
    
    //3.请求
    [manager GET:@"http://192.168.1.80/jiekou/server.php" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"JSON: %@", responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", error);
    }];

 

二、POST请求方式:

    //1.管理器
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
   
    //2.设置参数
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"param1"] = @"1";
    params[@"param2"] = @"2";
    
    //3.请求
    [manager POST:@"http://192.168.1.80/jiekou/server.php" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"JSON: %@", responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", error);
    }];

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM