Skip to content

Instantly share code, notes, and snippets.

@sungys
Created July 8, 2015 02:45
Show Gist options
  • Save sungys/738cd7c5b7537814e904 to your computer and use it in GitHub Desktop.
Save sungys/738cd7c5b7537814e904 to your computer and use it in GitHub Desktop.
@interface HttpClient : AFHTTPRequestOperationManager
+ (HttpClient *)sharedClient {
static HttpClient *_sharedClient = nil;
_sharedClient = [[HttpClient alloc] initWithBaseURL:[NSURL URLWithString:kRequestURLString]];
_sharedClient.responseSerializer.acceptableContentTypes = [_sharedClient.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
AFJSONResponseSerializer *responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];
[_sharedClient setResponseSerializer:responseSerializer];
return _sharedClient;
}
+(void) postHttpRequest:(NSString *)method
withParam:(NSDictionary *)paramRequest
withSuccess:(HttpClientSuccessBlock)success
withFailure:(HttpClientFailureBlock)failure {
NSMutableDictionary *paramBase = [[NSMutableDictionary alloc]initWithDictionary:paramRequest];
[[HttpClient sharedClient] POST:[[ApiClient sharedInstance] urlStringForApi:method] parameters:paramRequest success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"success");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if (failure) {
NSLog(@"errorResult");
}
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment