iOS AFN upload download detailed steps (2)

Source: Internet
Author: User

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)

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.