//Connection请求网络数据(系统)
-(void)NSURLConnectionPOST{
NSURL *url = [NSURL URLWithString:@”http://api.douban.com/v2/movie/top250“];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
[req setHTTPMethod:@"POST"];
req.HTTPBody = [@"start=0&count=2&apikey=02d830457f4a8f6d088890d07ddfae47" dataUsingEncoding:NSUTF8StringEncoding];
NSData *data = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:nil];
NSLog(@"%@",[NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil]);
}
//NSURLSession请求网络数据(系统);
-(void)NSURLSessionPOST{
NSURL *url = [NSURL URLWithString:@"http://api.douban.com/v2/movie/top250"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
[req setHTTPMethod:@"POST"];
req.HTTPBody = [@"start=0&count=2&apikey=02d830457f4a8f6d088890d07ddfae47" dataUsingEncoding:NSUTF8StringEncoding];
NSURLSession *sess = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [sess dataTaskWithRequest:req completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSLog(@"%@",[NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil]);
NSLog(@"--------------------------------\n%@",response);
}];
[task resume];
}
//AFHTTPRequestOperationManager请求网络数据(第三方);
-(void)AFHTTPRequestPOST{
AFHTTPRequestOperationManager *man = [AFHTTPRequestOperationManager manager];
[man POST:@”http://api.douban.com/v2/movie/top250” parameters:@{@”start”:@0,@”count”:@5} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@”%@”,responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
}