// 请求数据类实例化
AFHTTPSessionManager* manager = [AFHTTPSessionManagermanager];
// 可变request实例化
NSMutableURLRequest*request = [[NSMutableURLRequestalloc] initWithURL:[NSURLURLWithString:str]];
// 设置 请求方法我POST
request.HTTPMethod= @"POST";
// 设置请求头 的 Content-Type格式
[request setValue:@"application/x-www-form-urlencoded"forHTTPHeaderField:@"Content-Type"];
NSString*postStr = [NSStringstringWithFormat:@"content=%@",mdic];
[request setHTTPBody:[postStr dataUsingEncoding:NSUTF8StringEncoding]];
// 请求数据
NSURLSessionDataTask* dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse* _Nonnullresponse, id_NullableresponseObject, NSError* _Nullableerror) {
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
NSIntegerresponseStatusCode = [httpResponse statusCode];
// NSLog(@"---------%@ %ld %@", httpResponse, (long)responseStatusCode ,responseObject);
if(responseStatusCode == 200) {
// 成功后的处理
// NSLog(@"%@", responseObject);
// NSLog(@"返回数据为!!!%@" , responseObject);
successResponse(responseObject);
}else{
// 失败后的处理
// NSLog(@"%@", error);
if(error.code==-1009){
NSDictionary*codeDic=@{@"errCode":@"-1009",@"msg":@"网络未连接!"};
successResponse(codeDic);
}else{
NSDictionary*codeDic=@{@"errCode":APPERROR,@"msg":@"未知错误!"};
successResponse(codeDic);
}
}
}];
[dataTask resume];