0
我有在SAP瀏覽器中以XML格式打開的SAP業務連接器URL。當我在瀏覽器中粘貼SAP BU URL時,彈出窗口打開並詢問用戶ID和密碼。然後輸入密碼後顯示XML格式的數據。我知道如何解析iPhone中的XML文件,但該方法不適用於這個SAP網址。如何使用Obj-C解析iPhone中的SAP業務連接器鏈接?
從iPHone中使用xcode,objective C獲取用戶ID & pwd的這類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]);
}
好的......讓我試試 –
儘管它顯示DATA的字節長度,但我的鏈接沒有得到解析。以上編碼需要改變什麼? –
嗨Navnath,你可以在這裏發佈你的代碼,所以我們可以檢查是否有任何問題,也檢查你是否在瀏覽器中獲取數據可能是有一些與服務器URL的問題。 – prasad