2010-09-27 3 views
0

J'essaie de télécharger http://www.vesseltracker.com/earth/vesseltrackerlight.kmz mais je ne reçois pas tous les morceaux.NSURLConnection ne télécharge que les 567 premiers octets?

J'ai essayé:

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

en vain

puis passer à

- (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]; 
} 

Mais je suis hors de la chance. Il faut toujours 567 octets (devrait être autour de 4k) Je pense qu'il peut commencer à décompresser et échouer ....

Répondre

2

J'ai téléchargé l'URL que vous avez listée avec Safari et elle a seulement 567 octets de long. Basez-vous votre attente "4k" sur ce que dit la vue de la liste du Finder? Cet affichage n'est qu'approximatif en raison des tailles de blocs d'allocation de fichiers ... Le nombre réel d'octets du fichier est affiché entre parenthèses derrière cette valeur dans la fenêtre "Get Info ..." du fichier.

+0

Je l'ai téléchargé avec curl et j'ai obtenu le même résultat, donc ce n'est pas quelque chose de spécifique à WebKit-/Foundation; il semble que le fichier servi par le serveur ne soit réellement que de 567 octets. –

Questions connexes