标签:
直接上代码了。。。
在iOS7之后可以使用NSURLSession,但是考虑到兼顾iOS6还是使用NSURLConnection。
@interface ViewController() <NSURLConnectionDataDelegate> @property (nonatomic,strong) NSMutableData *receivedData; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0]; NSURLConnection *theConncetion=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; if (theConncetion) { _receivedData = [NSMutableData data]; } } -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [_receivedData appendData:data]; NSLog(@"Downloading..."); } -(void)connectionDidFinishLoading:(NSURLConnection *)connection { NSLog(@"Finished"); } @end
标签:
原文地址:http://blog.csdn.net/pleasecallmewhy/article/details/43267359