hi friends
In my contact management app i am using webservice to get a large xml data, that contains contact details. i use NSURLConnection class for sending requests. But i am facing problem in while getting the XML . First i get a broken XML and then I am getting the whole XML data . Can anyone figure out what is going wrong in my app. this is my piece of code that i am using.
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];
and
-(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];
}