以下に正しい方法でアプローチしているかどうかについて、簡単な意見をいただければ幸いです。
ある友人から、彼のスタートアップ企業のためにアプリを作成するのを手伝ってもらえないかと尋ねられました。彼らは、asp.netアプリケーションのフレーバーを実行しているサーバーを持っています。
彼は、ユーザーが自分のアカウントにログインして管理できる iOS アプリを望んでいます。
NSURLSession と NSURLSessionDataTask をチェックしています。
これが私がそれを実現するために必要なものです:
NSURL *url = [NSURL URLWithString:@"https://myfriendssite.com/Account/Login"];
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration:defaultConfigObject delegate:self delegateQueue: [NSOperationQueue mainQueue]];
NSURLSessionDataTask * dataTask = [defaultSession dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSLog(@"reponse: %@",response);
if(error == nil)
{
NSHTTPURLResponse *httpResp = (NSHTTPURLResponse*) response;
NSLog(@"code: %d", httpResp.statusCode);
NSString * text = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
[webView loadHTMLString:text baseURL:url];
NSLog(@"Data: %@",text);
}
else
{
NSLog(@"Error: %@", error);
}
}];
[dataTask resume];
}
[タスク再開] を使用してタスクを開始すると、タスクの「didReceiveChallenge」を受け取ります。そのとき、私は次のように答えます。
NSURLCredentialPersistence persistence = NSURLCredentialPersistenceNone;
NSURLCredential *credential = [NSURLCredential credentialWithUser:[usernameField text] password:[passworField text] persistence:persistence];
completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
しかし、応答で返される Cookie に関して何かをする必要がありますか?
"Set-Cookie" = "__RequestVerificationToken=cIxrC6dJnHyD6pIe-zgkx_Hr0CbsRZ7_dbQfsSIWsFAtVXjV_-o4d_2GycwhY0E-JjyA8R3iNsTreVOIcTNWQvxBenlEMLe8RJ5vz6JcyRSjLNn7H1Uklu0MD-afm08RVe7L8m4DzvtJv5rTAAie-w2; path=/; HttpOnly";
私はここで自分の要素からかなり外れているので、何かポインタをいただければ幸いです!
乾杯!
アダム