1 根据网址初始化OC字符串对象
    NSString * urlString = [NSString stringWithFormat:@"%@",kVideoURL];
   

2 创建URL对象
    NSURL * url = [NSURL URLWithString:urlString];
   

3 创建请求
    NSMutableURLRequest * requrst = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10];
   

4 创建参数字符串对象
    NSString * parmStr = [NSString stringWithFormat:@"%@",@"method=album.channel.get&appKey=myKey&format=json&channel=t&pageNo=1&pageSize=10"];
   

5 将字符串转为NSDATA 对象
    NSData * parmData = [parmStr dataUsingEncoding:NSUTF8StringEncoding];
   

6 设置请求体
    [requrst setHTTPBody:parmData];
   

7 设置请求方式
    [requrst setHTTPMethod:@"POST"];
    
   

创建同步连接  设置代理
     [NSURLConnection connectionWithRequest:requrst delegate:self];
    
服从代理

    @interface ViewController () <NSURLConnectionDataDelegate>
    @end


实现代理方法:

    

    当收到服务器响应时 触发
    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    获文件大小
    length = [response expectedContentLength];
    NSLog(@"%lld",length);
 
    当收到服务器响应时 , 为data 开辟空间 , 接下来服务器要返回数据
    self.data = [NSMutableData data];
}

    当收到服务器返回数据时触发  , 返回的可能是资源片段(此时该方法重复执行)
    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    //拼接数据
    [self.data appendData:data];
    
    CGFloat  rate = self.data.length * 1.0 / length;
    NSLog(@"%g",rate);
}

    当服务器返回所有数据后触发 . 数据返回完毕
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
   // self.data;//就是服务器返回的所有的数据


    //解析
   NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:self.data options:NSJSONReadingMutableContainers error:nil];
   // NSLog(@"%@",dic);
   
   此时数据已经全部获取, 假如数据时为tableViewCell 设置cell的内容 , 此时需要刷新 cell

    [tableView reloadData];


}

    服务器连接错误时触发
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
   NSLog(@"%d",4);
}