0

大家好,
我正在开发一个应该管理通过互联网下载内容的单例,我知道存在 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];
    }
}

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

4

0 回答 0