- (IBAction)getbigfile:(UIButton *)sender { NSString *str = @"http://b.hiphotos.baidu.com/video/pic/item/e850352ac65c1038698cd94eb7119313b17e894f.jpg"; NSURL *url = [NSURL URLWithString:str]; NSURLRequest * request = [[NSURLRequest alloc]initWithURL:url]; NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:YES]; [conn start]; }
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ self.receivedData = [[NSMutableData alloc]init]; }
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ [self.receivedData appendData:data]; NSLog(@"接受到服务器端来的数据%d",data.length); NSString *Data =[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"%@",Data); }
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{ NSLog(@"222"); NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/a.mp4"]; NSLog(@"string = %@",path); [self.receivedData writeToFile:path atomically:YES]; }
时间: 2024-10-10 09:34:18