IOS Rookie Learning Afnetworking (i)

Source: Internet
Author: User

Source code Download: http://download.csdn.net/detail/haogaoming123/8555077
As the asihttprequest stopped updating, many people turned to afnetworking and Mknetworkkit. I'm one of them. So I looked for a lot of articles from the Internet for reference, but the result is a failure. Study for a long time can not get through, and finally asked someone to help fix it. Often from the online request for free information, to have the idea of return, but also in order to let more people take a few detours, so the following is the code: (There are errors can be pointed out) First: Add afnetworking, uikit+afnetworking to the project and then where to use #import The post of "AFHTTPRequestOperationManager.h" #import "AFHTTPSessionManager.h" Afhttprequestoperationmanager has two methods,    One is the normal post, the other is can upload pictures of 1. Upload Image: Afhttprequestoperationmanager *manager = [Afhttprequestoperationmanagermanager];    Manager.responseSerializer.acceptableContentTypes = [nssetsetwithobject:@ "text/html"];    Nsdictionary *parameters [email protected]{@ "Parameter 1": @ "value1", @ "Parameter 2": @ "value2" 、、、};    NSData *imagedata = uiimagejpegrepresentation ([UIImage imagenamed:@ "1.png"], 1.0); [Manager post:@ "is replaced with the address you want to access" parameters:parametersconstructingbodywithblock:^ (id<afmultipartformdata>    FormData) {[FormData appendpartwithfiledata:imagedata name:@ "1" filename:@ "1.png" mimetype:@ "Image/jpeg"]; } success:^ (Afhttprequestoperation *operation,id responseobject) {        NSLog (@ "Success:%@", responseobject);    } failure:^ (Afhttprequestoperation *operation,nserror *error) {NSLog (@ "error:%@", error); }]; This method can upload pictures, if not upload pictures, you can remove this sentence [FormData appendpartwithfiledata:imagedataname:@ "1" filename:@ "1.png" mimetype:@ "    Image/jpeg "]2. Common Postafhttprequestoperationmanager *manager = [Afhttprequestoperationmanagermanager];   Manager.responseSerializer.acceptableContentTypes = [nssetsetwithobject:@ "text/html"];    Nsdictionary *parameters = @{@ "Parameter 1": @ "value1", @ "Parameter 2": @ "value2" 、、、}; [managerpost:@] replaced with the address you want to access "Parameters:parameters success:^ (afhttprequestoperation *operation,id responseObject)          {NSLog (@ "Success:%@", responseobject);          }failure:^ (afhttprequestoperation *operation,nserror *error) {NSLog (@ "error:%@", error); }];

IOS Newcomer Learning afnetworking (i)

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.