无法从服务器获取响应

时间:2016-01-29 04:19:43

标签: ios web-services

无法从服务器获得响应。

  NSMutableDictionary *dic =[[NSMutableDictionary alloc]init];
  NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;


  NSString *strvideo=[NSString stringWithFormat:@"https://player.vimeo.com/video/%@/config",arrVideoId[i]];
  [request2 setURL:[NSURL URLWithString:strvideo]];
  [request2 setHTTPMethod:@"GET"];

  NSData *body2 = [self encodeDictionary:dic2];
  [request2 setValue:[NSString stringWithFormat:@"%d", body2.length] forHTTPHeaderField:@"Content-Length"];
  [request2 setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
  [request2 setHTTPBody:body2];

  NSError *error;
  NSURLResponse *resultResponse;
  NSData *response2 = [NSURLConnection sendSynchronousRequest:request2 returningResponse:&resultResponse error:&error];

  NSMutableDictionary *dictResult2 =[NSJSONSerialization JSONObjectWithData:response2 options:NSJSONReadingMutableLeaves error:nil];

1 个答案:

答案 0 :(得分:0)

-(void)setImage
{
    array = [[NSMutableArray alloc]init];
    NSMutableDictionary *dictionary1 = [[NSMutableDictionary alloc]init];
    [dictionary1 setValue:@"img_home1.png" forKey:@"imageName"];
    [array addObject:dictionary1];
    NSMutableDictionary *dictionary2 = [[NSMutableDictionary alloc]init];
    [dictionary2 setValue:@"img_home2.png" forKey:@"imageName"];
    [array addObject:dictionary2];
for (int i = 0; i <= array.count; i++)
    {
        CGRect frame= CGRectZero; //self.scrollHomeView.frame;
        frame.origin.x = [[UIScreen mainScreen] bounds].size.width  * i;
        frame.origin.y = 0;
        frame.size.width=[[UIScreen mainScreen] bounds].size.width;
        frame.size.height = [[UIScreen mainScreen] bounds].size.height-130;

        UIImageView *image = [[UIImageView alloc] initWithFrame:frame];
        image.contentMode= UIViewContentModeScaleAspectFit;
[self.scrollHomeView addSubview:image];
}
    self.scrollHomeView.contentSize = CGSizeMake([[UIScreen mainScreen] bounds].size.width * array.count,self.scrollHomeView.frame.size.height-130);
    self.scrollHomeView.pagingEnabled = YES;
    self.scrollHomeView.showsHorizontalScrollIndicator = NO;
    self.scrollHomeView.showsVerticalScrollIndicator = NO;
    self.scrollHomeView.scrollsToTop = NO;
}