1 Five. AFN2 1. Get\post3 1>GET Request4 //1. Obtaining the Request Manager5Afhttprequestoperationmanager *mgr =[Afhttprequestoperationmanager manager];6 7 //2. Package Request Parameters8Nsmutabledictionary *params=[Nsmutabledictionary dictionary];9 params[@"username"] =@"123";Ten params[@"pwd"] =@"123"; One A //3. Send a GET request -[Mgr GET:@"Http://baidu.com/login"Parametersparams -success:^ (Afhttprequestoperation *operation,IDresponseobject) { theNSLog (@"Successful Request---%@", responseobject); - } -failure:^ (afhttprequestoperation *operation, Nserror *error) { -NSLog (@"request failed---%@", error); + }]; - + A 2>POST Request at //1. Obtaining the Request Manager -Afhttprequestoperationmanager *mgr =[Afhttprequestoperationmanager manager]; - - //2. Package Request Parameters -Nsmutabledictionary *params=[Nsmutabledictionary dictionary]; - params[@"username"] =@"123"; in params[@"pwd"] =@"123"; - to //3. Send a POST request +[Mgr POST:@"Http://baidu.com/login"Parametersparams -success:^ (Afhttprequestoperation *operation,IDresponseobject) { theNSLog (@"Successful Request---%@", responseobject); * } $failure:^ (afhttprequestoperation *operation, Nserror *error) {Panax NotoginsengNSLog (@"request failed---%@", error); - }]; the + 2. File Upload A //1. Obtaining the Request Manager theAfhttprequestoperationmanager *mgr =[Afhttprequestoperationmanager manager]; + - //2. Send the request (do file upload) $ #warningParameters: Only non-file parameters can be placed $Nsmutabledictionary *params=[Nsmutabledictionary dictionary]; - params[@"username"] =@"Zhangsan"; - the[Mgr POST:@"Http://baidu.com/upload"Parametersparams -constructingbodywithblock:^ (ID<AFMultipartFormData>formData) {Wuyi //Be sure to add the file parameter to this block the - //Loading File Data WuNSString *file = [[NSBundle mainbundle] Pathforresource:@"Test.txt"Oftype:nil]; -NSData *data =[NSData Datawithcontentsoffile:file]; About $ //Stitching file Parameters -[FormData appendpartwithfiledata:data Name:@"file"FileName:@"123.txt"MimeType:@"Text/plain"]; - } -success:^ (Afhttprequestoperation *operation,IDresponseobject) { ANSLog (@"upload successful----%@", responseobject); +} failure:^ (Afhttprequestoperation *operation, Nserror *error) { theNSLog (@"upload failed----%@", error); -}];
iOS AFN upload download detailed steps (2)