#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
AF-GET-POST
最新推荐文章于 2021-09-09 07:59:48 发布