Not used before, always feel very difficult to use after feeling is not too difficult, this article is just a simple talk about how to use,
//instance Session ObjectAfhttpsessionmanager *manager =[Afhttpsessionmanager Manager]; Manager.requestSerializer.timeoutInterval= -; Manager.responseserializer=[[Afhttpresponseserializer alloc] init]; Manager.responseSerializer.acceptableContentTypes= [Nsset setwithobjects:@"Application/json",@"Text/json",@"Text/javascript",@"text/html", nil]; //Add the parameters you need in the request headerNSString *token =[[Yxloginstatustool Sharedloginstatus] Gettokenid]; [Manager.requestserializer setvalue:token Forhttpheaderfield:@"ID"];//Request AddressNSString *urlstr =@""; [Manager post:urlstr Parameters:nil Constructingbodywithblock:^(ID<AFMultipartFormData>_nonnull FormData) {
Turn into data
Self.justimagedata = Uiimagepngrepresentation (pickerimagepic);
//write binary files into formdata form in form format[FormData appendPartWithFileData:self.justimagedata Name:@""FileName:@""MimeType:@"Image/png"]; [FormData appendPartWithFileData:self.backimagedata Name:@""FileName:@""MimeType:@"Image/png"]; } Progress:^ (Nsprogress *_nonnull uploadprogress) {Yxlog (@"++++%@+++", uploadprogress); } Success:^ (Nsurlsessiondatatask *task,IDresponseobject) {Yxlog (@"Responseobject = =%@--++--%@----", [self getresponseobjcwithtask:responseobject],[self getrespodheaderwithtask:task]); if([[Self getrespodheaderwithtask:task][@"Status"] Isequaltostring:@"1"]) { //Success}Else{[Yxalearmnager showalearviewwith:[self getrespodheaderwithtask:responseobject][@"errormsg"] Type:2]; } [Yxnetworkhud dismiss]; } Failure:^ (Nsurlsessiondatatask *task, Nserror *error) {[Yxnetworkhud dismiss]; Yxlog (@"Send failed +++++%@++++%@", error,[self Getrespodheaderwithtask:task]); [Yxalearmnager Showalearviewwith:@"Avatar Replacement failed"Type:2]; }];
//* * Get response header */- (ID) Getrespodheaderwithtask: (Nsurlsessiontask *) task{Nshttpurlresponse*respond = (Nshttpurlresponse *) Task.response; returnRespond.allheaderfields;}-(ID) Getresponseobjcwithtask: (ID) responseobect{IDJSON; Nserror*error; JSON= [Nsjsonserialization jsonobjectwithdata:responseobect options:0error:&ERROR]; if(Error) {JSON=[[NSString alloc] Initwithdata:responseobect encoding:nsutf8stringencoding]; } returnJSON;}
IOS submit Form form, upload image