同步请求数据 简介: 新建一个textView,用他来接收请求到的数据. //新建tv tv = [[UITextView alloc] initWithFrame: CGRectMake(0, 30, 320, 300)]; tv.text = @""; //使用asi同步请求数据 NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request startSynchronous]; NSError *error = [request error]; if (!error) { // Call this method to get the received data as an NSString. Don't use for binary data! NSString *response = [request responseString]; //添加数据到tv中显示 tv.text = [NSString stringWithString: response]; //显示图片 UIImageView *image = [[UIImageView alloc] initWithImage: [UIImage imageWithData: response]]; image.frame = CGRectMake(0, 50, 100, 50); [self.window addSubview: image]; }