Request Data Class instantiation
Afhttpsessionmanager * manager = [afhttpsessionmanager manager];
Variable Request instantiation
nsmutableurlrequest *request = [[nsmutableurlrequest alloc] initwithurl: [Nsurl urlwithstring: str]];
Set Request Method I post
Request. HttpMethod = @ "POST";
Set the Content-type format of the request header
[Request SetValue:@ "application/x-www-form-urlencoded" forhttpheaderfield:@ " Content-type "];
nsstring *poststr = [nsstring stringwithformat:@ "content=%@", MDic];
[Request Sethttpbody: [poststr datausingencoding:nsutf8stringencoding];
Request data
nsurlsessiondatatask * datatask = [Manager datataskwithrequest: Request Completionhandler: ^ ( nsurlresponse * _nonnull response, ID _nullable responseobject, nserror * _nullable error) {
nshttpurlresponse* HttpResponse = (nshttpurlresponse*) response;
nsinteger responsestatuscode = [HttpResponse statusCode];
NSLog (@ "---------%@%ld%@", HttpResponse, (Long) Responsestatuscode, responseobject);
if (responsestatuscode = =) {
// post-Success processing
NSLog (@ "%@", responseobject);
NSLog (@ " return data is!!! %@ ", responseobject);
Successresponse (Responseobject);
}Else {
// post-failure processing
//NSLog (@ "%@", error);
if(error. Code==-1009) {
nsdictionary *codedic=@{@ "Errcode":@ " -1009"@ "MSG":@ " Network not connected !" };
Successresponse (Codedic);
}Else{
nsdictionary *codedic=@{@ "Errcode":apperror,@ "MSG":@ " Unknown error !" };
Successresponse (Codedic);
}
}
}];
[Datatask resume];
Afnetworking application/x-www-form-urlencoded Data Request method