// MyHttpTool.h
// 新浪微博
//
// Created by jose on 15-3-30.
// Copyright (c) 2015年 jose. All rights reserved.
// 封装网络工具
#import <Foundation/Foundation.h>
@interface MyHttpTool : NSObject
//get请求
+(void)Get:(NSString *)url Params:(NSDictionary *)params Success:(void(^)(id responsedata))success Failure:(void(^)(NSError *error))failure;
//post请求
+(void)Post:(NSString *)url Params:(NSDictionary *)params Success:(void (^)(id responsedata))success Failure:(void(^)(NSError *error))failure;
@end
***************************************************************************************************************************************************************
**************************************************************************************************************************************************************
**************************************************************************************************************************************************************
//
// MyHttpTool.m
// 新浪微博
//
// Created by jose on 15-3-30.
// Copyright (c) 2015年 jose. All rights reserved.
//
#import "MyHttpTool.h"
#import "AFNetworking.h"
@implementation MyHttpTool
+(void)Get:(NSString *)url Params:(NSDictionary *)params Success:(void (^)(id))success Failure:(void (^)(NSError *))failure{
//获取请求管理
AFHTTPRequestOperationManager *mgr=[AFHTTPRequestOperationManager manager];
//get请求
[mgr GET:url parameters:params success:^(AFHTTPRequestOperation *operation,NSDictionary *response){
if (success) {
//NSLog(@"%@",response);
//block函数调用
success(response);
}
} failure:^(AFHTTPRequestOperation *operation,NSError *error){
if (failure) {
failure(error);
}
}];
}
+(void)Post:(NSString *)url Params:(NSDictionary *)params Success:(void (^)(id))success Failure:(void (^)(NSError *))failure{
//获取请求管理
AFHTTPRequestOperationManager *mgr=[AFHTTPRequestOperationManager manager];
//post请求
[mgr POST:url parameters:params success:^(AFHTTPRequestOperation *operation,NSDictionary *response){
if (success) {
success(response);
}
} failure:^(AFHTTPRequestOperation *operation,NSError *error){
if (failure) {
failure(error);
}
}];
}
@end