//Transfer data
1Afhttprequestoperationmanager *manager =[Afhttprequestoperationmanager manager];2Manager.responseserializer =[Afhttpresponseserializer serializer];3Manager.requestserializer =[Afhttprequestserializer serializer];4 5 //2. Set Login Parameters6Nsdictionary *dict = @{@"username": Username,@"Password":p Assword,@"Birthday": Birthday,@"Gender": Gender,@"Mobile": Mobile,@"Avstar": Avster};7 //3. Request8[Manager POST:@"Http://127.0.0.1/HelloServer/index.php/users/insert"Parameters:dict success: ^ (Afhttprequestoperation *operation,IDresponseobject) {9 TenNSString *result =[[NSString alloc] Initwithdata:responseobject encoding:nsutf8stringencoding]; OneNSLog (@"POST--%@,%@", result, [Nsthread CurrentThread]);//automatically return to main thread AUIWindow *window =[[UIApplication sharedapplication] Keywindow]; -Window.rootviewcontroller =[Appdelegate Tabbarcontroller]; - the} failure: ^ (afhttprequestoperation *operation, Nserror *error) { -NSLog (@"%@", error); -}];
//File Upload
1NSData *data =uiimagepngrepresentation (image);2NSDateFormatter *formatter =[[NSDateFormatter alloc] init];3Formatter.dateformat =@"YYYYMMDDHHMMSS";4NSString *str =[Formatter stringfromdate:[nsdate Date]];5NSString *filename = [NSString stringWithFormat:@"%@.png", str];6NSLog (@"filename:%@", fileName);7Afhttprequestoperationmanager *manager =[Afhttprequestoperationmanager manager];8Manager.responseserializer =[Afhttpresponseserializer serializer];9Manager.requestserializer =[Afhttprequestserializer serializer];Ten OneNsdictionary *parameters = @{@"Foo":@"Bar"}; A[Manager POST:@"http://localhost/HelloServer/index.php/index/upload/"Parameters:parameters constructingbodywithblock:^ (ID<AFMultipartFormData>formData) { -[FormData appendpartwithfiledata:data Name:@"file"Filename:filename MimeType:@"Image/png"]; -} success:^ (Afhttprequestoperation *operation,IDresponseobject) { theNSLog (@"Success:%@", responseobject); -} failure:^ (Afhttprequestoperation *operation, Nserror *error) { -NSLog (@"Error:%@", error); -}];
iOS development afnetworking for data transfer and file upload