#import
#import "AFNetworking.h"
typedef void(^NetworkingSuccess)(id response);
typedef void(^NetworkingFail)(NSError *error);
@interface NetworkingTools : NSObject
+ (void)postRequestWithURL:(NSString *)url parameters:(NSDictionary *)parameters success:(NetworkingSuccess)success fail:(NetworkingFail)fail;
+ (void)getRequestWithURL:(NSString *)url parameters:(NSDictionary *)parameters success:(NetworkingSuccess)success fail:(NetworkingFail)fail;
@end
#import "NetworkingTools.h"
@implementation NetworkingTools
+ (void)postRequestWithURL:(NSString *)url parameters:(NSDictionary *)parameters success:(NetworkingSuccess)success fail:(NetworkingFail)fail {
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer.acceptableContentTypes= [NSSet setWithObjects:@"text/html", nil];
[manager POST:url parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
success(responseObject);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
fail(error);
}];
}
+ (void)getRequestWithURL:(NSString *)url parameters:(NSDictionary *)parameters success:(NetworkingSuccess)success fail:(NetworkingFail)fail {
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer.acceptableContentTypes= [NSSet setWithObjects:@"text/html", nil];
[manager GET:url parameters:parameters progress:^(NSProgress * _Nonnull downloadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
success(responseObject);
}failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
fail(error);
}];
}
@end