我有 SAP 业务连接器 URL,它在浏览器中以 XML 格式打开。当我在浏览器中粘贴 SAP BU URL 时,弹出窗口会打开询问用户 ID 和密码。然后在输入密码后它会显示 XML 格式的数据。我知道如何在 iPhone 中解析 XML 文件,但该方法不适用于此 SAP url。
使用 xcode、objective C 从 iPHone 中具有用户 ID 和密码的此类 url 获取数据所需的步骤是什么?
用代码更新
- (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]);
}