构造URL网络地址
NSURL *url = [NSURL URLWithString:@"http://piao.163.com/m/cinema/list.html?app_id=1&mobileType=iPhone&ver=2.6&channel=appstore&deviceId=9E89CB6D-A62F-438C-8010-19278D46A8A6&apiVer=6&city=110000"];
构造网络请求对象 NSURLRequest
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
//设置请求方式 POST
request.HTTPMethod = @"POST";
//设置请求的超时时间
request.timeoutInterval = 60;
//设置请求体
NSString *bodyString = @"cinema_id=1533";
//将字符串 转化为NSData
request.HTTPBody = [bodyString dataUsingEncoding:NSUTF8StringEncoding];
通过配置对象构造网络会话 NSURLSession
NSURLSession *session = [NSURLSession sharedSession];
创建网络任务 NSURLSessionTask
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
//JSON解析
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
NSLog(@"%@", dic);
}];
发起网络任务
[dataTask resume];