0

私はiphoneでbigcommerceapiを使用してそこからデータをフェッチしているので、xml解析の助けを借りてそれを行っていますが、注文のリストを取得するには、bigcommerce Webサイトへのログインを要求し、誰かがこれで私を助けてくれればデータを解析しますそれから私は非常に感謝します、私たちがログイン資格情報を送信する方法をxml解析して教えてくださいそしてそれからデータを解析するためにurlを押してください.....

ありがとうございました

私はこのコードを書いています

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
// Add the navigation controller's view to the window and display.
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];

// Override point for customization after application launch.
NSString *string=[NSString stringWithFormat:@"https://www.labradorhometraining.com/api/v2"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:string]];

//    NSString *dataString = [NSString stringWithFormat:@"{\"screenName\":\"%@\",\"password\":\"%@\",\"pushToken\":\"%@\",\"deviceType\":\"%@\"}", Screentxtf.text,passtxtf.text,  str, deviceType];

[request setRequestMethod:@"GET"];
[request appendPostData:[string dataUsingEncoding:NSUTF8StringEncoding]];
// Basic YWRtaW46cGFzc3dvcmQ=
 [request addRequestHeader:@"Content-Type" value:@"application/xml"];
[request addRequestHeader:@"Authorization: Basic ZGVtb2tleTpkZW1vdG9rZW4= " value:[NSString stringWithFormat:@"%@ %@",@"api", @"c275ab4076f87"]];
[request setUseSessionPersistence:NO];
[request setUseCookiePersistence:NO];
[request setCacheStoragePolicy:ASICacheForSessionDurationCacheStoragePolicy];
[request setDelegate:self];
[request startAsynchronous];
return YES;
}

これはルートビューコントローラにあります

-(void)gototselect{
NSString *string=[NSString stringWithFormat:@"https://www.labradorhometraining.com/api/v2/orders.xml"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:string]];

//    NSString *dataString = [NSString stringWithFormat:@"{\"screenName\":\"%@\",\"password\":\"%@\",\"pushToken\":\"%@\",\"deviceType\":\"%@\"}", Screentxtf.text,passtxtf.text,  str, deviceType];

[request setRequestMethod:@"PUT"];
//    [request appendPostData:[string dataUsingEncoding:NSUTF8StringEncoding]];
[request addRequestHeader:@"Authorization" value:[NSString stringWithFormat:@"%@ %@",@"api", @"c2714076f87"]];
[request allowCompressedResponse];
[request setUseSessionPersistence:NO];
[request setUseCookiePersistence:NO];
[request setCacheStoragePolicy:ASICacheForSessionDurationCacheStoragePolicy];
[request setDelegate:self];
[request startAsynchronous];

}
4

1 に答える 1

1

私は ASIHTTPRequest API について何も知りませんし、自分のキャリアで使用したこともありません。しかし、プレーンな Objective-C を使用して、http 要求を認証する方法についていくつかのコードを共有します。

// Setup NSURLConnection
NSURL *URL = [NSURL URLWithString:url];
 NSURLRequest *request = [NSURLRequest requestWithURL:URL
                                     cachePolicy:NSURLRequestUseProtocolCachePolicy
                                 timeoutInterval:30.0];

NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
[connection release];

// NSURLConnection Delegates
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
if ([challenge previousFailureCount] == 0) {
    NSLog(@"received authentication challenge");
    NSURLCredential *newCredential = [NSURLCredential credentialWithUser:@"USER"
                                                                password:@"PASSWORD"
                                                             persistence:NSURLCredentialPersistenceForSession];
    NSLog(@"credential created");
    [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
    NSLog(@"responded to authentication challenge");    
}
else {
    NSLog(@"previous authentication failure");
}
}

 - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse  *)response {
...
}

 - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
...
}

 - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
...
 }

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
...
}

上記のコードは、iOS の NSURLConnection および Basic HTTP Authenticationからコピーしたこのリンクです。また、いくつかのリンクをあなたと共有したいと思います。HTTP リクエストについては Apple のドキュメントを参照してくださいhttp://developer.apple.com/library/mac/#documentation/cocoa/conceptual/URLLoadingSystem/Articles/AuthenticationChallenges.html そして、この投稿http://www.cocoanetics.com/2010/12 /nsurlconnection-with-self-signed-certificates/ .. この作業に関する多くの情報と戦術が得られます。

于 2013-03-11T11:29:17.703 に答える