Last active
August 25, 2016 01:18
-
-
Save qyzhaojinxi/a15cf9dce73f3f439c57707b227a5317 to your computer and use it in GitHub Desktop.
AFNetWorking请求数据方式 #json #非json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+(void)getServerTimeWithCompletionBlock:(void (^)(BOOL success, id object))completionBlock | |
{ | |
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; | |
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:configuration]; | |
// manager.securityPolicy.allowInvalidCertificates = YES; | |
NSString *url=[NSString stringWithFormat:@"%@caller/server_time.php",KRootApi]; | |
manager.responseSerializer = [AFHTTPResponseSerializer serializer];//处理非json数据 | |
manager.responseSerializer.acceptableContentTypes=[NSSet setWithObjects:@"application/json", @"text/html",@"text/json", @"text/javascript",@"text/plain", nil]; | |
NSMutableDictionary *dic=[NSMutableDictionary new]; | |
// [dic setObject:type forKey:@"item"]; | |
// [dic setObject:topicId forKey:@"id"]; | |
[dic addEntriesFromDictionary:[self getParam]]; | |
NSMutableURLRequest *request=[[AFHTTPRequestSerializer serializer]requestWithMethod:@"POST" URLString:url parameters:dic error:nil]; | |
NSURLSessionDataTask *dataTask=[manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { | |
NSLog(@"%@",error.description); | |
NSString *str=[[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding]; | |
NSDictionary *dic=[EZNetEngine happy_base64_decode:str]; | |
if (error) { | |
completionBlock(false,dic); | |
}else | |
{ | |
completionBlock(true,dic); | |
} | |
}]; | |
[dataTask resume]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment