网络请求之AFNetworking封装

HTTPRequest.h

//请求成功回调
typedef void(^RequestSuccessCallBack)(id resposeObject);
//请求失败回调
typedef void(^RequestErrorCallBack)(NSError *error);
@interface HTTPRequest : NSObject
/**
 *  GET请求
 *
 *  @param urlString url地址
 *  @param parameter 参数
 *  @param success   成功回调
 *  @param failure   失败回调
 */
+(void)GET:(NSString *)urlString parameter:(NSDictionary *)parameter success:(RequestSuccessCallBack)success failure:(RequestErrorCallBack)failure;


HTTPRequest.m

#import "HTTPRequest.h"
#import 

@implementation HTTPRequest
/**
 *  GET请求
 *
 *  @param urlString url地址
 *  @param parameter 参数
 *  @param success   成功回调
 *  @param failure   失败回调
 */
+(void)GET:(NSString *)urlString parameter:(NSDictionary *)parameter success:(RequestSuccessCallBack)success failure:(RequestErrorCallBack)failure{

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    [manager GET:urlString parameters:parameter progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (success) {
            success(responseObject);
        }   
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
        }
    }];
}

你可能感兴趣的:(网络请求之AFNetworking封装)