ios項目繞過認證訪問https程式,ios繞過認證https

來源:互聯網
上載者:User

ios項目繞過認證訪問https程式,ios繞過認證https

如果是單個的webview或者request請求,在請求的檔案h中直接實現NSURLConnectionDelegate,並在m中添加下列實現下列兩個方法:

 

 

C代碼  
  • - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {  
  •     return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];  
  • }  
  •   
  • - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {  
  •     if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])  
  •         //if ([trustedHosts containsObject:challenge.protectionSpace.host])  
  •             [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]   
  •                  forAuthenticationChallenge:challenge];    
  •     [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];  
  • }  
  • - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {    return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];}- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])        //if ([trustedHosts containsObject:challenge.protectionSpace.host])            [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]                  forAuthenticationChallenge:challenge];      [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];}

     上述方法很不爽的是每個請求的地方都要加。

     

    如果項目中用到了three20,直接修改“TTRequestLoader.m”即可,這個檔案本身就已經實現了NSURLConnectionDelegate,

     

    修改如下,只改這一個地方就行,處處可用。

     

     

    C代碼  
  • ///////////////////////////////////////////////////////////////////////////////////////////////////  
  • - (void)connection:(NSURLConnection *)connection  
  • didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{  
  •     //修改  
  •     if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])  
  •         [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];  
  •     [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];  
  •       
  •     TTDCONDITIONLOG(TTDFLAG_URLREQUEST, @"  RECEIVED AUTH CHALLENGE LOADING %@ ", _urlPath);  
  •     [_queue loader:self didReceiveAuthenticationChallenge:challenge];  
  • }  
  •   
  • //添加  
  • - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {  
  •     return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];  
  • }  
  • ///////////////////////////////////////////////////////////////////////////////////////////////////- (void)connection:(NSURLConnection *)connectiondidReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{    //修改    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])        [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];    [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];        TTDCONDITIONLOG(TTDFLAG_URLREQUEST, @"  RECEIVED AUTH CHALLENGE LOADING %@ ", _urlPath);    [_queue loader:self didReceiveAuthenticationChallenge:challenge];}//添加- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {    return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];}

     


    ios https為何要忽略認證

    [安全、許可權]ASIHTTPRequest 如何忽略認證,請求https?
    出現問題如題。
    步驟如下:
    1.在伺服器上配置https網站,使用的自訂認證。
    2.在ios用戶端使用ASIHTTPRequest架構

    www.devdiv.com/...170776
     
    XP禁用http網頁訪問但允許https的訪問,不通過第三方軟體可以實現?

    內建防火牆自訂規則
     

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.