iOS 封装AFNetworking请求数据
#import "AFNetworking.h" + (void)GET:(NSString *)URLString parameters:(id)parameters success:(void (^)(id))success failure:(void (^)(NSError *))failure { // 创建请求管理者 AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager]; [mgr GET:URLString parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { // AFN请求成功时候调用block // 先把请求成功要做的事情,保存到这个代码块 if (success) { success(responseObject); } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { if (failure) { failure(error); } }]; } + (void)Post:(NSString *)URLString parameters:(id)parameters success:(void (^)(id))success failure:(void (^)(NSError *))failure { // 创建请求管理者 AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager]; [mgr POST:URLString parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { if (success) { success(responseObject); } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { if (failure) { failure(error); } }]; } + (void)Upload:(NSString *)URLString parameters:(id)parameters uploadParam:(CZUploadParam *)uploadParam success:(void (^)(id))success failure:(void (^)(NSError *))failure { // 创建请求管理者 AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager]; [mgr POST:URLString parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {// 上传的问价全部在这里拼接 formData /** * FileData :就是要上传的二进制的数据 * * name: jiushi就是上传参数的名称 * * filename :上传文件类型 */ [formData appendPartWithFileData:uploadParam.data name:uploadParam.name fileName:uploadParam.fileName mimeType:uploadParam.mineType]; } success:^(AFHTTPRequestOperation *operation, id responseObject) { if (success) { success(responseObject); } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { if (failure) { failure(error); } }]; }