0
    NSURLCredential *credential2 = [NSURLCredential
                  credentialForTrust:challenge.protectionSpace.serverTrust
                  credentialWithUser: @"username"
                                            password: @"password"
                                         persistence:NSURLCredentialPersistenceNone];


    [challenge.sender useCredential:credential2 forAuthenticationChallenge:challenge];

UIWebViewで自己署名証明書をバイパスすると同時に、認証用のユーザー名とパスワードを渡す必要があります。

 NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];

NSURLCredential * credential = [NSURLCredential credentialWithUser:@ "username" password:@ "password" persistence:NSURLCredentialPersistenceNone];

私がそれらを組み合わせようとすると、両方とも単独で有効であり、両方とも大騒ぎします...何かアイデアはありますか?

4

1 に答える 1

0

この問題を解決するには、RestKit と以下のコードをログイン資格情報の alertView と共に使用しました。

- (id)initWithURL:(NSURL*)pageURL {

    _retainedURL = pageURL;
    [_retainedURL retain];

    RKClient *client;
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    client = [RKClient clientWithBaseURL: pageURL];
    client.username=[userDefaults objectForKey:@"UserName"];
    client.password=[userDefaults objectForKey:@"Password"];
    client.authenticationType=RKRequestAuthenticationTypeHTTPBasic;
    client.disableCertificateValidation= TRUE;
    RKRequest *request=[RKRequest requestWithURL:pageURL delegate:self];
    [client configureRequest:request];
    request.authenticationType = RKRequestAuthenticationTypeHTTPBasic;
    request.disableCertificateValidation = TRUE;
    self.authenticatedRequest = request;
    [request sendAsynchronously];

    if(self = [super init]) {
        self.URL = pageURL;
        self.availableActions = SVWebViewControllerAvailableActionsOpenInSafari | SVWebViewControllerAvailableActionsMailLink | SVWebViewControllerAvailableActionsCopyLink;
    }
    return self;
}

login alertView は、ユーザー名とパスワードのテキストを userdefaults に追加し、保持された URL を initWithURL 関数に戻します。ログインアラートビューは、ページが認証されていないときに呼び出されています (ログイン資格情報を使用)。

于 2012-11-20T19:30:53.370 に答える