1
#import <Foundation/Foundation.h>

main() {
        NSURL *url = [NSURL URLWithString:@"http://www.google.com/"]; 
        NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url                
            cachePolicy:NSURLRequestReloadIgnoringCacheData  
                timeoutInterval:60]; 

        NSURLResponse *response; 
        NSError *error; 
        NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 
        NSLog(@"Data were download below:\n%@", [[NSString alloc] initWithData:data encoding: NSASCIIStringEncoding]); 
}

运行可执行文件->数据下载如下:[null]

为什么?

4

1 回答 1

0

您是否尝试过分配请求和错误?

NSURLResponse *response = [[NSURLResponce alloc] init];

NSError *error = [[NSError alloc] init];

于 2015-09-11T17:36:06.440 回答