AF-GET-POST

来源:互联网 发布:武汉斗鱼招聘 php 编辑:程序博客网 时间:2024/04/29 07:55
#import "SNViewController.h"#import "AFNetworking.h"@interface SNViewController ()@end@implementation SNViewController- (void)viewDidLoad{    [super viewDidLoad];}-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{    [self postQuery];}-(void)postQuery{    //1.获得请求管理者    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];        //2.声明服务器返回的数据是JSON    mgr.responseSerializer = [AFJSONResponseSerializer serializer];        NSMutableDictionary *params = [NSMutableDictionary dictionary];    params[@"pagemark"] = @"20150105";        //3.发送POST请求    [mgr POST:@"http://www.hnjgdj.gov.cn/mobileChannel_findGongwei.do" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {        NSLog(@"success");    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {        NSLog(@"error");    }];        }-(void)getQuery{    //1.获得请求管理者    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];        //2.封装请求参数    NSMutableDictionary *params = [NSMutableDictionary dictionary];    params[@"pagemark"] = @"20150105";        //3.发送GET请求    [mgr GET:@"http://www.hnjgdj.gov.cn/mobileChannel_findGongwei.do" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {        NSLog(@"success----%@", responseObject[@"retcode"]); //responseObject 是一个字典或者是数组    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {        NSLog(@"error----%@", error);    }];    }@end

0 0
原创粉丝点击