ASIHTTPRequestErrorDomain code 1

用域名连,不行。查了下有人解决了:



http://stackoverflow.com/questions/8538449/asihttprequesterrordomain-code-1



In my app, i'm trying to connect to a IIS server to access some servers. Whe i run the app in iOS 4 or earlier the connection works fine, but wen i run in iOS 5, the connection retorn this erro:

Error Domain=ASIHTTPRequestErrorDomain Code=1 "A connection failure occurred" UserInfo=0x6b601d0 {NSUnderlyingError=0x6b5fe20 "The operation couldn’t be completed. (OSStatus error -9836.)", NSLocalizedDescription=A connection failure occurred}

this is the code that i call.

self.currentRequest = [ASIHTTPRequest requestWithURL:url];
[self.currentRequest setValidatesSecureCertificate:NO];
[self.currentRequest setDelegate:self];
[self.currentRequest setUsername:credentials.login];
[self.currentRequest setPassword:credentials.password];
[self.currentRequest setDomain:@"CORP"];
[self.currentRequest setUseHTTPVersionOne:YES];
[self.currentRequest setTimeOutSeconds:120];
[self.currentRequest startAsynchronous];

Samebody have an idea why this is happening?

Thank's

share | improve this question
 
I see you are using ASI. I'm not sure about this specific error, but I do know ASIHTTPRequest needs the "libz.dylib" library to be a part of the project dependencies in iOS 5.0. –  Stavash  Dec 16 '11 at 20:52
feedback

1 Answer

-9836 is a bad protocol error. It's probably due to iOS 5's implementation of TLS being upgraded to TLS 1.2. If TLS 1.2 isn't supported by the server it may terminate the handshake and fail to downgrade to a supported protocol level.

In ASIHTTPRequest.m change to the following in - (void)startRequest

//
// Handle SSL certificate settings
//

if([[[[self url] scheme] lowercaseString] isEqualToString:@"https"]) {       

    NSDictionary *sslProperties = [[NSDictionary alloc] initWithObjectsAndKeys:
                                   @"kCFStreamSocketSecurityLevelTLSv1_0SSLv3", (NSString *)kCFStreamSSLLevel,
                                   nil];

    CFReadStreamSetProperty((CFReadStreamRef)[self readStream], 
                            kCFStreamPropertySSLSettings, 
                            (CFTypeRef)sslProperties);

    // Tell CFNetwork not to validate SSL certificates
    if (![self validatesSecureCertificate]) {
        // see: http://iphonedevelopment.blogspot.com/2010/05/nsstream-tcp-and-ssl.html

        NSDictionary *sslProperties = [[NSDictionary alloc] initWithObjectsAndKeys:
                                  [NSNumber numberWithBool:YES], kCFStreamSSLAllowsExpiredCertificates,
                                  [NSNumber numberWithBool:YES], kCFStreamSSLAllowsAnyRoot,
                                  [NSNumber numberWithBool:NO],  kCFStreamSSLValidatesCertificateChain,
                                  kCFNull,kCFStreamSSLPeerName,
                                  @"kCFStreamSocketSecurityLevelTLSv1_0SSLv3", (NSString *)kCFStreamSSLLevel,
                                  nil];

        CFReadStreamSetProperty((CFReadStreamRef)[self readStream], 
                                kCFStreamPropertySSLSettings, 
                                (CFTypeRef)sslProperties);
    }

    // Tell CFNetwork to use a client certificate
    if (clientCertificateIdentity) {
        NSMutableDictionary *sslProperties = [NSMutableDictionary dictionaryWithCapacity:2];

        NSMutableArray *certificates = [NSMutableArray arrayWithCapacity:[clientCertificates count]+1];

        // The first object in the array is our SecIdentityRef
        [certificates addObject:(id)clientCertificateIdentity];

        // If we've added any additional certificates, add them too
        for (id cert in clientCertificates) {
            [certificates addObject:cert];
        }

        [sslProperties setObject:certificates forKey:(NSString *)kCFStreamSSLCertificates];
        [sslProperties setObject:@"kCFStreamSocketSecurityLevelTLSv1_0SSLv3" forKey:(NSString *)kCFStreamSSLLevel];

        CFReadStreamSetProperty((CFReadStreamRef)[self readStream], kCFStreamPropertySSLSettings, sslProperties);
    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值