2014-01-08 1 views
-1

저는 HTTPS 요청을 받았습니다.IOS에서 HTTPS로 sendasynchronousrequest를 처리합니까?

sendAsynchronousRequestNSURLConnection입니다. 그때마다 나는 다음과 같은 오류 여기

NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9806) 
CFNetwork SSLHandshake failed (-9806) 

을 얻고있다 NSURLConnectionsendAsynchronousRequest을 사용하고 언제

NSURL *url=[NSURL URLWithString:strService]; 

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; 
[theRequest setHTTPMethod:@"POST"]; 
NSString *msgLength = [NSString stringWithFormat:@"%d", [strSoap length]]; 

[theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];; 

[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; 

[theRequest setValue:@"My User-Agent" forHTTPHeaderField:@"User-Agent"]; 
[theRequest addValue:strSoapAction forHTTPHeaderField:@"SOAPAction"]; 
[theRequest setHTTPBody: [strSoap dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:TRUE]]; 

[NSURLConnection sendAsynchronousRequest:theRequest queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *resp, NSData *responseData, NSError *error) { 
    NSString *strResponse=[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding] ; 


    strResponse=[self clearHtmlTags:strResponse]; 

    NSMutableDictionary *dictResponse=[NSMutableDictionary dictionaryWithDictionary:[NSDictionary dictionaryWithXMLString:strResponse]]; 

    block(dictResponse); 
}]; 

이를 내 코드입니다

NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 

을 사용하지 않으 sendAsynchronousRequest를 사용하여 NSURLConnection의 대리자 메서드를 호출하는 다른 방법은 무엇입니까?

답변

0

이 대리자 메서드를 추가해보십시오. 희망이 당신을 위해 작동합니다.

- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge 
{ 
    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { 

     // Verify certificate: 
     SecTrustResultType trustResult; 
     OSStatus status = SecTrustEvaluate(challenge.protectionSpace.serverTrust, &trustResult); 
     BOOL trusted = (status == errSecSuccess) && ((trustResult == kSecTrustResultProceed) || (trustResult == kSecTrustResultUnspecified)); 

     if (trusted) { 
      [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] 
       forAuthenticationChallenge:challenge]; 
     } else { 
      if (1) { 
       [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] 
        forAuthenticationChallenge:challenge]; 
      } else { 
       [challenge.sender cancelAuthenticationChallenge:challenge]; 
      } 
     } 
    } else { 
     [challenge.sender performDefaultHandlingForAuthenticationChallenge:challenge]; 
    } 
} 
+0

이 경우 위임을 설정해야합니까? –

+0

이것은 대리자 메서드이므로 호출되지 않습니다. –

+0

왜 호출되지 않습니까? .h 파일에'NSURLConnectionDataDelegate' 프로토콜을 추가해야합니다. –