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

AFNetworking 使用总结

时间:2014-10-23 22:18:17      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:http   io   ar   使用   sp   on   art   log   cti   

NSString *URLTmp = @"";

    NSString *URLTmp1 = [URLTmp stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];  //转码成UTF-8  否则可能会出现错误

    URLTmp = URLTmp1;

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString: URLTmp]];

    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

        NSLog(@"Success: %@", operation.responseString);

        NSString *requestTmp = [NSString stringWithString:operation.responseString];

        NSData *resData = [[NSData alloc] initWithData:[requestTmp dataUsingEncoding:NSUTF8StringEncoding]];

        //系统自带JSON解析

        NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:resData options:NSJSONReadingMutableLeaves error:nil];

        

         NSLog(@"resultDic: %@", resultDic);

        

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

        NSLog(@"Failure: %@", error);

       // [SVProgressHUD dismissWithError:@"提交失败,请重试"];

    }];

    [operation start];

AFNetworking 使用总结

标签:http   io   ar   使用   sp   on   art   log   cti   

原文地址:http://www.cnblogs.com/jiackyan/p/4046742.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!