- Tell the truth I am disgusted with this kind of wonderful writing, because of the project requirements of the wonderful and the staff to leave the big pit is no language, do not want the next or this is the pit.
- Import the AFN file first or pod.
Nsdictionary *parameters; Parameters= @{@"type":@"GetPath",@"Path": _path}; //set the parameters according to your server's format settingsNSString *temp = [NSString stringWithFormat:@"{\"Type\": \ "getpath\", \ "path\": \ "%@\"}", _path];NSData*data =[temp datausingencoding:nsutf8stringencoding]; NSString*requesturl = [NSString stringWithFormat:@"%@%@"The URL of the weburl_prefix,weburl_getdir];//request I copied it directly from the code so this should know how to get it afurlsessionmanager*manager =[[Afurlsessionmanager alloc] Initwithsessionconfiguration:[nsurlsessionconfiguration Defaultsessionconfiguration]]; If you do not need to pass through the body then the parameters into the parameters inside Nsmutableurlrequest*request = [[Afhttprequestserializer serializer] Requestwithmethod:@"POST"Urlstring:requesturl Parameters:nil Error:nil]; NSLog (@"requesturl:%@", Requesturl); Request.timeoutinterval=Ten; [Request SetValue:@"Application/json"Forhttpheaderfield:@"Content-type"]; //set the body here to put the parameters into the body[Request Sethttpbody:data]; Afhttpresponseserializer*responseserializer =[Afhttpresponseserializer Serializer]; Responseserializer.acceptablecontenttypes= [Nsset setwithobjects:@"Application/json", @"text/html", @"Text/json", @"Text/javascript", @"Text/plain", nil]; Manager.responseserializer=Responseserializer; [Manager datataskwithrequest:request Uploadprogress:nil downloadprogress:nil Completionhandler:^ (Nsurlresponse *response,IDResponseobject,nserror *error) { if(responseobject!=Nil) {NSString*result =[[NSString alloc] Initwithdata:responseobject encoding:nsutf8stringencoding]; Nsdictionary*jsondict =[nsjsonserialization jsonobjectwithdata:responseobject options:nsjsonreadingmutableleaves Error:nil]; NSString*type = [Jsondict objectforkey:@"type"]; NSString*path = [Jsondict objectforkey:@"Path"]; if([Type isequaltostring:@"GetPath"]) { if([path Isequaltostring:_path]) {_disklist= [Jsondict Objectforkey:@"Disk"]; _folderlist= [Jsondict Objectforkey:@"folder"]; _documentlist= [Jsondict Objectforkey:@"Document"]; NSLog (@"%@",@"path is correct"); }Else{NSLog (@"%@",@"path is not correct"); } }Else{NSLog (@"%@",@"type is not GetPath"); } [Self.tableview Reloaddata]; NSLog (@"%@", result); }}]resume];
IOS AFN Pass parameters to the server via body