-(void)YiZhouBoYanViedoData{
NSURL * url = [NSURL URLWithString:@"http://47.92.242.41:520/TwEightShare/Index.php"];
NSMutableURLRequest * requestUrl = [NSMutableURLRequest requestWithURL:url];
requestUrl.HTTPMethod = @"POST";
NSMutableDictionary * dict = [NSMutableDictionary dictionary];
[dict setObject:@"2002" forKey:@"eight"];
[dict setObject:self.YiZhouBoYanTypeString forKey:@"type"];
NSString * string = [self YiZhouBoYanparameters:dict];
NSData * data = [string dataUsingEncoding:NSUTF8StringEncoding];
requestUrl.HTTPBody = data;
[requestUrl setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSURLSession * session = [NSURLSession sharedSession];
NSURLSessionDataTask * dataTask = [session dataTaskWithRequest:requestUrl completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (!error) {
dispatch_async(dispatch_get_main_queue(), ^{
NSDictionary * dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
NSArray * array = dict[@"d"];
NSMutableArray * tempArray = [NSMutableArray array];
for (NSDictionary * modelDict in array) {
YiZhouBoYanViedoInfoModel * model = [[YiZhouBoYanViedoInfoModel alloc]init];
[model setValuesForKeysWithDictionary:modelDict];
[tempArray addObject:model];
}
self.YiZhouBoYanVideoArray = tempArray;
[self.YiZhouBoYanMyTableView reloadData];
});
}
}];
[dataTask resume];
}
-(NSString *)YiZhouBoYanparameters:(NSDictionary *)parameters
{
//创建可变字符串来承载拼接后的参数
NSMutableString *parameterString = [NSMutableString new];
//获取parameters中所有的key
NSArray *parameterArray = parameters.allKeys;
for (int i = 0;i < parameterArray.count;i++) {
//根据key取出所有的value
id value = parameters[parameterArray[i]];
//把parameters的key 和 value进行拼接
NSString *keyValue = [NSString stringWithFormat:@"%@=%@",parameterArray[i],value];
if (i == parameterArray.count || i == 0) {
//如果当前参数是最后或者第一个参数就直接拼接到字符串后面,因为第一个参数和最后一个参数不需要加 “&”符号来标识拼接的参数
[parameterString appendString:keyValue];
}else
{
//拼接参数, &表示与前面的参数拼接
[parameterString appendString:[NSString stringWithFormat:@"&%@",keyValue]];
}
}
return parameterString;
}
网友评论