Dans mon application de gestion des contacts, j'utilise le service Web pour obtenir des données XML volumineuses contenant des informations de contact. J'utilise la classe NSURLConnection pour envoyer des requêtes. Mais je suis confronté à un problème lors de l'obtention du XML. D'abord, je reçois un XML brisé et ensuite j'obtiens toutes les données XML. Quelqu'un peut-il comprendre ce qui ne va pas dans mon application. c'est mon morceau de code que j'utilise.Obtention de code XML rompu suivi d'un code XML complet à partir du service Web
NSData *postData = [postFields dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:[[NSString alloc] initWithString:Url]]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
[request setHTTPBody:postData];
conn = nil;
conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
et
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[myData appendData:data];
NSString *theXml = [[NSString alloc] initWithData:myData encoding:NSASCIIStringEncoding];
UIAlertView *thealert = [[UIAlertView alloc] initWithTitle:@"the xml" message:theXml delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
[thealert show];
[thealert release];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:data];
[xmlParser setDelegate:self];
[xmlParser parse];
[xmlParser release];
}
merci ... Je suis allé à travers la documentation .. et le problème a été résolu. J'ai appelé l'analyseur de connectionDidFinishLoading: méthode conn et son fonctionnement maintenant ... – user347161