(IOS-Network) Basic HTTP Implementation Method of AFNetWorking network framework, ios-afnetworking
Summarize the basic usage of AFNetworking.
① In AppDelegate. h, import the AFHTTPRequestOperationManager. h file and add an attribute manager:
@property (strong,nonatomic(AFHTTPRequestOperationManager *)manager;
Complete manager initialization in Application: didFinishLauchingWithOpertions: In the implementation file:
self.manager = [AFHTTPRequestOperationManager manager];
② Import AppDelegate. h where data needs to be loaded using HTTP to implement the following statement:
AppDelegate = [UIApplication sharedApplication]. delegate;
NSString * str_input_data = [NSString stringWithFormat: @ "238549_21963 $2053 $11 $ % @$ %@% %@ $ None $ %@ $ O10.001 $ %@$ %@% %@$ %@ $ % @", ageCode, sexCode, nationCode, marryCode, symCode, self. highBPField. text, self. lowBPField. text, self. rateField. text, self. temperatureField. text, self. breathField. text]; NSString * temStr = [NSString stringWithFormat: @ "http: // url? Str_input_data = % @ ", str_input_data]; // str_input_data is the interface NSString * encoded = [temStr stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; // The URL that can be identified must undergo UTF-8 encoding conversion [appDelegate. manager GET: encoded parameters: nil success: ^ (AFHTTPRequestOperation * operation, id resonseObject ){
// The received responseObject is processed here. It is already a parsed json file with resultKeys = [NSMutableArray array]; resultValues = [NSMutableArray array]; NSArray * array = resonseObject; for (NSInteger j = 0; j <array. count; j ++) {if (j % 2 = 0) {[resultKeys addObject: [array objectAtIndex: j];} else if (j % 2 = 1 &&! [(NSString *) array [j] isEqual: @ "0"]) {// [resultValues addObject: [array objectAtIndex: j]; [resultValues addObject :( NSString *) array [j];} else {break;} NSLog (@ "keys = % @, value = % @", resultKeys, resultValues); [self. resultTable reloadData];} failure: ^ (AFHTTPRequestOperation * operation, NSError * error) {NSLog (@ "connection diagnosis result service error: % @", error);}];