使用NSURLConnection和服务器信任身份验证质询的问题

时间:2011-07-12 09:35:22

标签: iphone authentication nsurlconnection trust

每个人的好日子,
我正在研究应该通过互联网管理内容下载的单例,我知道存在ASIHttp请求,这是一个很好的库,但我有自己的理由不使用它。
这个类工作得非常好,除了一件事:我正在尝试处理我的MobileMe帐户的公共文件夹而没有成功。我在其中上传了一个文件并尝试使用我的班级下载。 阅读有关stackOF和阅读文档的一些问题我进入了该代码,但它似乎不起作用:

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
    if([protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
    {
        NSLog(@"SERVER TRUST AUTH");
        return YES;
    }
    else if([protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodHTTPBasic])
    {
        NSLog(@"HTTP BASIC AUTH");
        return YES;
    }
    NSLog(@"NO AUTH");
    return NO;
}

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge

{
    NSLog(@"Authetication");

    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
    {
        NSLog(@"Trust Challange");
        SecTrustResultType trustResultType;
        OSStatus err=SecTrustEvaluate(challenge.protectionSpace.serverTrust, &trustResultType);

        NSLog(@"SecTrustResult %lu %ld",trustResultType,err);

        if (trustResultType == kSecTrustResultProceed || trustResultType == kSecTrustResultConfirm || trustResultType == kSecTrustResultUnspecified) {
            [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
        }
        else{
            [challenge.sender cancelAuthenticationChallenge:challenge];
        }


       // [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];

    }
    else if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodHTTPBasic])
    {
        NSLog(@"HTTP Challenge");
        NSURLCredential *credential = [[NSURLCredential alloc] initWithUser:@"user" password:@"pass" persistence:NSURLCredentialPersistenceForSession];
        [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
        [credential release];
    }
    else{
        [[challenge sender]cancelAuthenticationChallenge:challenge];
    }
}

现在我被卡住了,因为从日志中我可以看到evaluate函数返回的结果为4,对应于kSecTrustResultUnspecified,但即使我对挑战发件人说continueWithoutCredentialForAuthenticationChallenge,也没有任何工作。 该文件的URL是:https://public.me.com/XXXX/Objective.zip(已删除链接)zip是我在课堂上实现的ObjectiveZip库。
有什么建议吗?

0 个答案:

没有答案