基本認証を使用して https Web サービス (RESTful) を呼び出そうとしています。URL自体に資格情報を入力しても問題なく動作しますが、例外などでパスワードが表示されないように、リクエストに追加したいと思います。
次のコードを使用しています。
NSURLCredential *credential = [NSURLCredential credentialWithUser:@"myuser"
password:@"mypassword"
persistence:NSURLCredentialPersistenceForSession];
NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
initWithHost:@"example.com"
port:443
protocol:@"https"
realm:nil
authenticationMethod:NSURLAuthenticationMethodHTTPBasic];
[[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential:credential
forProtectionSpace:protectionSpace];
NSURLConnection *theConnection = [NSURLConnection connectionWithRequest:theRequest delegate:self];
しかし、それは機能しません。didReceiveAuthenticationChallengeデリゲート メソッドが呼び出され、そこに資格情報を追加できますが、理想的には、要求と共に送信します。
何か案は?