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)