IOS初级:AFNetworking
狗 日的,第三方框架真j8难搞
1.为什么NS_ASSUME_NONNULL_BEGIN在6.2报错,你他么的还挑IDE,你这是什么态度?
2.还有,你他么的自动给老子转json了,有问过我么?
#import "ViewController.h" #import "AFNetworking/AFNetworking.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; NSString *strUrl=[NSString stringWithFormat:@"http://demo.com/app/index.php/app_ios_0_1/userInfo"]; AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; NSDictionary *dict = @{@"uid":@"1"}; manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/plain"]; [manager GET:strUrl parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject){ NSLog(@"%@",operation.request.allHTTPHeaderFields); NSLog(@"%@",operation.response); NSLog(@"%@",responseObject); NSLog(@"get key uname = %@",[responseObject objectForKey:@"uname"]); }failure:^(AFHTTPRequestOperation *operation,NSError *error){ NSLog(@"%@",error); }]; [self networkStatus]; } -(void)networkStatus{ [[AFNetworkReachabilityManager sharedManager] startMonitoring]; [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status){ NSLog(@"status=%d",status); }]; }
2015-10-01 00:26:49.287 afnet[906:20954] status=2
2015-10-01 00:26:49.418 afnet[906:20954] {
"Accept-Language" = "en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5";
"User-Agent" = "afnet/1 (iPhone Simulator; iOS 8.2; Scale/2.00)";
}
2015-10-01 00:26:49.419 afnet[906:20954] <NSHTTPURLResponse: 0x7a67bba0> { URL: http://demo.com/app/index.php/app_ios_0_1/userInfo?uid=1 } { status code: 200, headers {
Connection = "Keep-Alive";
"Content-Encoding" = gzip;
"Content-Length" = 112;
"Content-Type" = "text/plain; charset=UTF-8";
CpuTime = 28;
Date = "Wed, 30 Sep 2015 16:26:04 GMT";
"Keep-Alive" = "timeout=1, max=100";
Server = "Apache/2";
Vary = "Accept-Encoding,User-Agent";
"X-Powered-By" = "PHP/5.2.17";
} }
2015-10-01 00:26:49.420 afnet[906:20954] {
message = ok;
pwd = fea7f657f56a2a448da7d4b535ee5e279caf3d9a;
response = 200000;
uid = 1;
uname = liuyi;
}
2015-10-01 00:26:49.420 afnet[906:20954] get key uname = liuyi
2015-10-01 00:26:49.418 afnet[906:20954] {
"Accept-Language" = "en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5";
"User-Agent" = "afnet/1 (iPhone Simulator; iOS 8.2; Scale/2.00)";
}
2015-10-01 00:26:49.419 afnet[906:20954] <NSHTTPURLResponse: 0x7a67bba0> { URL: http://demo.com/app/index.php/app_ios_0_1/userInfo?uid=1 } { status code: 200, headers {
Connection = "Keep-Alive";
"Content-Encoding" = gzip;
"Content-Length" = 112;
"Content-Type" = "text/plain; charset=UTF-8";
CpuTime = 28;
Date = "Wed, 30 Sep 2015 16:26:04 GMT";
"Keep-Alive" = "timeout=1, max=100";
Server = "Apache/2";
Vary = "Accept-Encoding,User-Agent";
"X-Powered-By" = "PHP/5.2.17";
} }
2015-10-01 00:26:49.420 afnet[906:20954] {
message = ok;
pwd = fea7f657f56a2a448da7d4b535ee5e279caf3d9a;
response = 200000;
uid = 1;
uname = liuyi;
}
2015-10-01 00:26:49.420 afnet[906:20954] get key uname = liuyi