0
因此,这里是我的问题:NSURL连接会/不会加载数据
我跟着iPhone开发者文档几乎到T的NSURLConnection tutorial,它只是有点工作。
这里就是这一切都错了:
对象似乎是正确的,并委托给connectionDidFinishLoading创建的,但任何URL我尝试加载的响应数据最终总是只为0字节。如果这有什么不同,我正在模拟器中运行。
这里是我的相关代码:
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"WVFS Player";
//create a request
NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://wvfs.josh-kaplan.com/nowPlaying.php"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
// create a connection
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(theConnection) {
// create the datum
responseData=[[NSMutableData data] retain];
} else {
// code this later
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[responseData setLength:0];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// make it work
NSLog(@"Succeeded! Received %d bytes of data:",[responseData length]);
// release it
[connection release];
[responseData release];
}
这是我的日志输出:
[Session started at 2010-03-14 09:01:09 -0400.]
2010-03-14 09:01:14.784 WVFS[19571:207] Succeeded! Received 0 bytes of data:
任何想法?