How to parse SAP business connector link in iPhone using Obj-C?

北慕城南 提交于 2019-12-12 05:48:38

问题


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 & pwd 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]);

}

回答1:


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");

}


来源:https://stackoverflow.com/questions/12178574/how-to-parse-sap-business-connector-link-in-iphone-using-obj-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!