AFNetWorking网络请求
NetWorkAPIClient.h #import <Foundation/Foundation.h> #import "AFHTTPRequestOperationManager.h" #define POST_PATH @"/campus/dispatch.rpc" #define BASE_URL @"http://192.168.0.102:8080/idc/mobile/"//测试环境 @interface NetWorkAPIClient : AFHTTPRequestOperationManager + (NetWorkAPIClient *)sharedClient; @end NetWorkAPIClient.m #import "NetWorkAPIClient.h" @implementation NetWorkAPIClient + (NetWorkAPIClient *)sharedClient { static NetWorkAPIClient *_sharedClient = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _sharedClient = [[NetWorkAPIClient alloc] initWithBaseURL:[NSURL URLWithString:BASE_URL]]; }); return _sharedClient; } @end HttpRequestService.h typedef void (^SuccessBlock)(id result); typedef void (^FailedBlock)(NSError *error); + (void)postTest:(SuccessBlock)success failed:(FailedBlock)failed; HttpRequestService.m #import "NetWorkAPIClient.h" + (void)postTest:(SuccessBlock)success failed:(FailedBlock)failed { NSDictionary *parameters=[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@",@"xxx"],@"userId", [NSString stringWithFormat:@"%@",nil],@"userName", [NSString stringWithFormat:@"%d",xxx],@"type",nil]; [[NetWorkAPIClient sharedClient] POST:GET_USER_INFO_PATH parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { success(responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; } // 使用 -(void)requestUserInfoTest { [HttpRequestService postTest:^(id result) { NSDictionary *dataDic = result; NSLog(@"dataDic %@",dataDic); }failed:^(NSError *error) { }]; }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。