(IOS-Network) Basic HTTP Implementation Method of AFNetWorking network framework, ios-afnetworking

Source: Internet
Author: User

(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);}];

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.