gpt4 book ai didi

cocoa - NSURLConnection 只下载前 567 个字节?

转载 作者:行者123 更新时间:2023-12-03 17:44:22 26 4
gpt4 key购买 nike

我正在尝试下载http://www.vesseltracker.com/earth/vesseltrackerlight.kmz但我没有得到所有的细节。

我尝试过:

  NSData *data = [NSData dataWithContentsOfURL: serverURL options: 0 error: &error];

没用

然后切换到

- (void)startDownloadingURL:(NSURL*) url
{
// Create the request.
NSURLRequest *theRequest = [NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];

// create the connection with the request
// and start loading the data
NSLog(@"SNNetworkController.startDownloadingURL [%@]", url);
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
// Create the NSMutableData to hold the received data.
// receivedData is an instance variable declared elsewhere.
receivedData = [[NSMutableData data] retain];
} else {
// inform the user that the download failed.
NSLog(@"SNNetworkController.startDownloadingURL Download failed!");
}
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
// This method is called when the server has determined that it
// has enough information to create the NSURLResponse.

// It can be called multiple times, for example in the case of a
// redirect, so each time we reset the data.

// receivedData is an instance variable declared elsewhere.
[receivedData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
// Append the new data to receivedData.
// receivedData is an instance variable declared elsewhere.
[receivedData appendData:data];
}

- (void)connection:(NSURLConnection *)connection
didFailWithError:(NSError *)error
{
// release the connection, and the data object
[connection release];
// receivedData is declared as a method instance elsewhere
[receivedData release];

// inform the user
NSLog(@"SNNetworkController.didFailWithError Download failed! Error - %@",
[error localizedDescription]);
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// do something with the data
// receivedData is declared as a method instance elsewhere
NSLog(@"SNNetworkController.downloadDidFinish Succeeded! Received %d bytes of data",[receivedData length]);

// release the connection, and the data object
[connection release];
[receivedData release];
}

但我运气不好。它总是需要 567 字节(应该在 4k 左右)我认为它可能会开始解压并失败......

最佳答案

我用 Safari 下载了您列出的 URL,它只有 567 字节长。您的“4k”期望是否基于 Finder ListView 的内容?由于文件分配 block 大小的原因,该显示只是近似值...文件的实际字节数显示在文件的“获取信息...”窗口中该值后面的括号中。

关于cocoa - NSURLConnection 只下载前 567 个字节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3807206/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com