ブラウザでXML形式で開くSAPビジネスコネクタのURLがあります。SAP BU URLをブラウザに貼り付けると、ポップアップが開き、ユーザーIDとパスワードを尋ねられます。次に、パスワードを入力すると、XML形式のデータが表示されます。iPhoneでXMLファイルを解析する方法を知っていますが、その方法はこのSAPURLでは機能しません。
xcode、Objective Cを使用してiPHoneでユーザー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]);
}