2012-02-27 60 views
0

我需要設法繞過/ ignor自簽名證書幫助..我還到處找,找不到任何爲我迄今爲止的工作..如何忽略自簽名證書使用的NSURLRequest

我努力實現這個here但林不知道如何使用此代碼

@implementation NSURLRequest(AllowAllCerts) 

+ (BOOL) allowsAnyHTTPSCertificateForHost:(NSString *) host { 
    return YES; 
} 

@end 

我把它添加到我的應用程序代理,但後來我不知道該怎麼辦?

任何幫助,將不勝感激。目前,因爲一切都沒有工作對我來說,我不使用任何

..

+0

在發佈問題前使用「搜索」功能。 – HelmiB 2012-02-27 04:15:50

+0

我做了............ – 2012-02-27 19:14:06

回答

1

這是我如何得到它的工作。 我在這個方法的下面添加了這兩個方法,我打電話給我的連接開始。

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace { 
    return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]; 
} 

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

    [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge]; 

    [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge]; 
} 
+1

注意..如果你這樣做,蘋果將不會接受你提交的代碼。希望這回答你的問題。 – 2012-02-27 02:08:34

+0

您可能想在發佈之前先搜索答案。 – HelmiB 2012-02-27 04:16:34

+0

我已經搜查了這個,並試了幾次..實際的代碼有第二種方法中的兩個if語句..我只是後來發現,你不得不刪除兩個if語句才能使它工作.. :( – 2012-02-27 19:13:11