0
在我的聯繫人管理應用程序中,我使用webservice獲取包含聯繫人詳細信息的大型xml數據。我使用NSURLConnection類來發送請求。但是我在獲取XML時遇到問題。首先,我得到一個破損的XML,然後我得到了整個XML數據。任何人都可以弄清楚我的應用程序出了什麼問題。這是我使用的一段代碼。從webservice獲取破損的XML,然後是完整的XML
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];
和
-(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];
}
thanx ...可以..我去通過文件..和問題已被解決。我從connectionDidFinishLoading:conn方法調用瞭解析器,現在它正在工作...... – user347161 2010-07-14 12:43:40