XML parsing on iphone with authenticator id

I am doing xml parsing while my url authenticates the url with username and password.

When I put this URL in a browser, it asks me for a username and password for login.

I want to parse this url in iphone using NSXMLParser .

For parsing, I use the code below, but for me it returns a parseErrorOccured error.

NSString *UploadCardDesign=kLOGIN_URL; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:UploadCardDesign]] autorelease]; [request setHTTPMethod: @"GET"]; [request setHTTPBody:nil]; NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; //NSString *strRequ=[[NSString alloc] initWithData:returnData encoding:nsen] NSString *data=[[NSString alloc]initWithData:returnData encoding:NSUTF8StringEncoding]; 

And for parsing:

 xmlParser = [[NSXMLParser alloc] initWithData:returnData]; [xmlParser setDelegate:self]; [xmlParser parse]; 

Please help me for the same or let me know what I'm doing for good results.

+4
source share
1 answer

Implement this delegate function for authentication ....

 - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { if ([challenge previousFailureCount] == 0) { NSLog(@"received authentication challenge"); NSURLCredential *newCredential; newCredential=[NSURLCredential credentialWithUser:@"root" password:@"rootpassword" persistence:NSURLCredentialPersistenceForSession]; NSLog(@"credential created"); [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge]; NSLog(@"responded to authentication challenge"); } else { NSLog(@"previous authentication failure"); UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Authentication Failure" message:@"Website did not accept the username and password." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; } } 
+2
source

Source: https://habr.com/ru/post/1380756/


All Articles