#pragma mark - body方式请求
/**
*异步POST请求:以body方式,支持数组
*
*@param url请求的url
*@param bodybody数据
*@param success成功回调
*@param failure失败回调
*/
- (void)RequestBodyWithUrl:(NSString*)url requestType:(ZJRequestType)requestType body:(NSData*)body success:(SuccessBlock)success failure:(void(^)(NSError*error))failure
{
NSString*requestUrl = [NSStringstringWithFormat:@"%@%@",DomainURL, url];
AFURLSessionManager*manager = [[AFURLSessionManageralloc]initWithSessionConfiguration:[NSURLSessionConfigurationdefaultSessionConfiguration]];
NSArray*typeArr =@[@"GET",@"POST",@"PUT",@"DELETE"];
NSMutableURLRequest*request = [[AFHTTPRequestSerializerserializer]requestWithMethod:typeArr[requestType]URLString:requestUrlparameters:nilerror:nil];
request.timeoutInterval=20;
[requestsetValue:@"application/json"forHTTPHeaderField:@"Content-Type"];
[requestsetValue:ShareTokenforHTTPHeaderField:@"token"];
//设置body
[requestsetHTTPBody:body];
AFHTTPResponseSerializer*responseSerializer = [AFHTTPResponseSerializerserializer];
responseSerializer.acceptableContentTypes= [NSSetsetWithObjects:@"application/json",
@"text/html",
@"text/json",
@"text/javascript",
@"text/plain",
nil];
manager.responseSerializer= responseSerializer;
[[managerdataTaskWithRequest:requestcompletionHandler:^(NSURLResponse*_Nonnullresponse,id_NullableresponseObject,NSError*_Nullableerror) {
if(!error) {
NSDictionary*resultDict = [responseObjectmj_JSONObject];
success(resultDict);
[[UIApplicationsharedApplication]setNetworkActivityIndicatorVisible:NO];
}else{
failure(error);
[[UIApplicationsharedApplication]setNetworkActivityIndicatorVisible:NO];
}
}]resume];
}
typedefenum{
GETType =0,
POSTType =1,
PUTType =2,
DELETEType =3
}ZJRequestType ;