标签:同步 post 请求
创建POST请求
1 根据网址初始化OC字符串对象
NSString * urlString = [NSString stringWithFormat:@"%@",kVideoURL];
2 创建URL对象
NSURL * url = [NSURL URLWithString:urlString];
3 创建请求
NSMutableURLRequest * requrst = [NSMutableURLRequest requestWithURL:url];
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"];
创建同步连接
NSData * data = [NSURLConnection sendSynchronousRequest:requrst returningResponse:nil error:nil];
解析
NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSLog(@"%@",dic);
标签:同步 post 请求
原文地址:http://qccccc.blog.51cto.com/6004423/1552612