I have SAP business connector URL which opens in XML format in browser. When I paste SAP BU URL in browser, the pop up opens with asking user ID and password. Then after entering the password it shows XML format data. I know how to parse XML file in iPhone but that method is not working with this SAP URL.
What are the steps required to fetch data from this kind of URL which have User ID & password in iPHone using xcode, objective C?
Updated with Code
- (void)applicationDidFinishLaunching:(UIApplication *)application {
self.myURL = [NSURL URLWithString:@"https://connect- test.com....."];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:self.myURL
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:60];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
// Configure and show the window
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge {
NSLog(@"received authentication challenge");
NSURLCredential *newCredential;
newCredential=[NSURLCredential credentialWithUser:@"User"
password:@"pwd"
persistence:NSURLCredentialPersistenceForSession];
[[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
NSLog(@"responded to authentication challenge");
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
self.ZSETIK = [[NSMutableData alloc] init];
NSLog(@"%@ ZSETIK",ZSETIK);
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[ZSETIK appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[ZSETIK release];
[connection release];
// [textView setString:@"Unable to fetch data"];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
//NSURL *myURL = [NSURL URLWithString:@"https://connect- test.hettich.com/invoke/ZSETIK/main? vendor=su&material=100200300&purchaseorderno=4502892791"];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:self.ZSETIK];
//Initialize the delegate.
XMLParser *parser = [[XMLParser alloc] initXMLParser];
//Set delegate
[xmlParser setDelegate:parser];
//Start parsing the XML file.
BOOL success = [xmlParser parse];
if(success)
NSLog(@"No Errors");
else
NSLog(@"Error Error Error!!!");
NSLog(@"Succeeded! Received %d bytes of data",[ZSETIK
length]);
}
Use asynchronous NSURLConnection, following NSURLConnectionDelegate will get called in this case, provide username and password and you will get xml response.
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
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");
}