Using afnetworking to request network data in iOS development

Source: Internet
Author: User

1, drag and drop afnetworking files into the project (note that different versions of the method, the process is based on version 2013);

2, the use of #import "AFNetworking.h" command to include afnetworking.h= in;

3. Complete code:

1 //2 //VIEWCONTROLLER.M3 //Network Requests4 //5 //Created by Mac on 16/5/12.6 //copyright©2016 year MZW. All rights reserved.7 //8 9 #import "ViewController.h"Ten #import "AFNetworking.h" One  A @interfaceViewcontroller () -  - @end the  - @implementationViewcontroller -  -- (void) Viewdidload { + [Super Viewdidload]; -      + //1. First create a string, connect the base URL and the interface URL. ANSString *urlstring = [@"http://tl.bearapp.cn"Stringbyappendingstring:@"/api/index/zdmc.php"]; at //2. Generate a URL using the string created above -Nsurl *url =[Nsurl urlwithstring:urlstring]; - //3. Create a request Management Object -Afhttprequestoperationmanager *manager = [[Afhttprequestoperationmanager Alloc]initwithbaseurl:url];//If you initialize using the Manager class method here, you should pass in the URL after the get command - //4. Create Parameters -Nsdictionary *DICC = [[Nsdictionary Alloc]initwithobjectsandkeys:@"er sha",@"title", nil]; in //5. Access to resources -[Manager GET:@"SDF"PARAMETERS:DICC success:^ (Afhttprequestoperation *operation,IDresponseobject) { toNSLog (@"%@", Responseobject);//If successful, prints the obtained results +} failure:^ (Afhttprequestoperation *operation, Nserror *error) { -NSLog (@"%@", error);//if it fails, print the wrong information the     }]; *  $ }Panax Notoginseng  - @end

Using afnetworking to request network data in iOS development

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.